Allow Full Access check in keyboards iOS10

你。 提交于 2019-11-28 09:28:20

iOS11 and above is easy.

iOS10 Solution: Check all the copy-able types, if one of them is available, you have full access otherwise not.

-- Swift 4.2--

override var hasFullAccess: Bool
{
    if #available(iOS 11.0, *){
        return super.hasFullAccess// super is UIInputViewController.
    }

    if #available(iOSApplicationExtension 10.0, *){
        if UIPasteboard.general.hasStrings{
            return  true
        }
        else if UIPasteboard.general.hasURLs{
            return true
        }
        else if UIPasteboard.general.hasColors{
            return true
        }
        else if UIPasteboard.general.hasImages{
            return true
        }
        else  // In case the pasteboard is blank
        {
            UIPasteboard.general.string = ""

            if UIPasteboard.general.hasStrings{
                return  true
            }else{
                return  false
            }
        }
    } else{
        // before iOS10
        return UIPasteboard.general.isKind(of: UIPasteboard.self)
    }
}

I have fixed this issue. iOS 10.0 and Swift 3.0

func isOpenAccessGranted() -> Bool {

    if #available(iOSApplicationExtension 10.0, *) {
        UIPasteboard.general.string = "TEST"

        if UIPasteboard.general.hasStrings {
            // Enable string-related control...
            UIPasteboard.general.string = ""
            return  true
        }
        else
        {
            UIPasteboard.general.string = ""
            return  false
        }
    } else {
        // Fallback on earlier versions
        if UIPasteboard.general.isKind(of: UIPasteboard.self) {
            return true
        }else
        {
            return false
        }

    }

}

Use like this:-

if (isOpenAccessGranted())
{
   print("ACCESS : ON")
}
else{
   print("ACCESS : OFF")
}

For friends, searching solution in Objective-C, Here it is

NSOperatingSystemVersion operatingSystem= [[NSProcessInfo processInfo] operatingSystemVersion];

if (operatingSystem.majorVersion>=10) {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = @"Hey";

    if (pasteboard.hasStrings) {
        pasteboard.string = @"";
        return true;
    }
    else
    {
        pasteboard.string = @"";
        return false;
    }
}
else
{
    return [UIPasteboard generalPasteboard];
}

P.S.: This is just a workaround

Tested on iOS 10 Swift 3.0 and iOS 9

Use #available(iOS 10.0, *) instead of #available(iOSApplicationExtension 10.0, *)

func isOpenAccessGranted() -> Bool {
    if #available(iOS 10.0, *) {
        var originalString = UIPasteboard.general.string
        if(!(originalString != nil)){
            originalString = ""
        }
        UIPasteboard.general.string = "Test"

        if UIPasteboard.general.hasStrings {
            UIPasteboard.general.string = originalString
            return true
        }else{
            return false
        }
    }else{
        return UIPasteboard.general.isKind(of: UIPasteboard.self)
    }
}

Swift 3

static func isOpenAccessGranted() -> Bool {
    if #available(iOS 10.0, iOSApplicationExtension 10.0, *) {
        let value = UIPasteboard.general.string
        UIPasteboard.general.string = "checkOpenedAccess"

        let hasString = UIPasteboard.general.string != nil
        if let _ = value, hasString {
            UIPasteboard.general.string = value
        }
        return hasString
    }
    else {
        return UIPasteboard(name: UIPasteboardName(rawValue: "checkOpenedAccess"), create: true) != nil
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!