How to check the “Allow Full Access” is enabled in iOS 8?

后端 未结 15 1191
醉酒成梦
醉酒成梦 2020-12-02 07:53

In iOS 8, when develop a custom keyboard and set RequestsOpenAccess property to YES in info.plist, there is a toggle button at Settings-> Add New Keyboard named \"Allow Full

相关标签:
15条回答
  • 2020-12-02 08:18

    For iOS 10 (Beta 5) they changed the UIPasteboard API but I found the following to work:

    let originalString = UIPasteboard.general.string
    UIPasteboard.general.string = "TEST"
    if UIPasteboard.general.hasStrings
    {
        UIPasteboard.general.string = originalString
        hasFullAccess = true
    }
    else
    {
         hasFullAccess = false
    }
    
    0 讨论(0)
  • 2020-12-02 08:21

    Update: No need for App Group to be enabled, as others have mentioned, just check for access to the pasteboard:

    - (BOOL)isFullAccessGranted
    {
        return !![UIPasteboard generalPasteboard];
    }
    

    NOTE: The following no longer works, even if you do have App Group enabled...

    For a custom keyboard with an App Group enabled, the following is a quick, reliable way of testing for the state of the "Allow Full Access" switch:

    func isOpenAccessGranted() -> Bool {
        let fm = NSFileManager.defaultManager()
        let containerPath = fm.containerURLForSecurityApplicationGroupIdentifier(
                            "group.com.example")?.path
        var error: NSError?
        fm.contentsOfDirectoryAtPath(containerPath!, error: &error)
        if (error != nil) {
            NSLog("Full Access: Off")
            return false
        }
        NSLog("Full Access: On");
        return true
    }
    
    0 讨论(0)
  • 2020-12-02 08:29

    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)
        }
    }
    
    0 讨论(0)
提交回复
热议问题