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

后端 未结 15 1192
醉酒成梦
醉酒成梦 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:11

    UPDATE 08/23/2017 for iOS 10 compatibility:

    func isOpenAccessGranted() -> Bool{
        UIPasteboard.general.string = "CHECK"
        return UIPasteboard.general.hasStrings
    }
    

    iOS 8:

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

    Please note that the simulator will always tell you that you have Full Access so for this to work properly you need to run it from a device.

    0 讨论(0)
  • 2020-12-02 08:11

    I've been testing this today in iOS 10 and getting access to the pasteboard doesn't appear to be enough. In iOS 10 you can set the pasteboard to a var without full access. Here's a solution I came up with...

    func checkFullAccess() -> Bool
    {
        var hasFullAccess = false
        if #available(iOSApplicationExtension 10.0, *) {
            let pasty = UIPasteboard.general
            if pasty.hasURLs || pasty.hasColors || pasty.hasStrings || pasty.hasImages {
                hasFullAccess = true
            } else {
                pasty.string = "TEST"
                if pasty.hasStrings {
                    hasFullAccess = true
                    pasty.string = ""
                }
            }
        } else {
            // Fallback on earlier versions
            var clippy : UIPasteboard?
            clippy = UIPasteboard.general
            if clippy != nil {
                hasFullAccess = true
            }
        }
        return hasFullAccess
    }
    

    Testing to see if the pasteboard has some content returns false with full access off, even when there's content on the pasteboard. Of course it could actually be empty so after all those tests you can safely attempt to set something on the pasteboard without worrying about replacing something that's already there. If you do have access and the pasteboard had content then the test would have returned true, if you don't have access then you can't overwrite something that was there.

    HTH, Mike

    0 讨论(0)
  • 2020-12-02 08:11

    For iOS 10 using Swift 2.3 (if you don't want to convert your files to Swift 3.0)

    func isOpenAccessGranted() -> Bool {
        if #available(iOSApplicationExtension 10.0, *) {
    
        let originalString = UIPasteboard.generalPasteboard().string
        UIPasteboard.generalPasteboard().string = "Test"
    
        if UIPasteboard.generalPasteboard().hasStrings {
                UIPasteboard.generalPasteboard().string = originalString
                return true
            } else {
                return false
            }
        } else {
            return UIPasteboard.generalPasteboard().isKindOfClass(UIPasteboard)
        }
    }
    
    0 讨论(0)
  • 2020-12-02 08:11

    For those of you who are using iOS 10 and Objective-C this will work as intended.

    - (BOOL)hasFullAccess
    {
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        NSString *originalString = pasteboard.string;
        pasteboard.string = @"TEST";
        if (pasteboard.hasStrings) {
            pasteboard.string = originalString;
            return YES;
        } else {
            return NO;
        }
    }
    
    0 讨论(0)
  • 2020-12-02 08:13

    A swift solution

     if let test = UIPasteboard.generalPasteboard() as? UIPasteboard{
            NSLog("Full Access: On")
            return true
        }else{
            NSLog("Full Access: Off")
            return false
        }
    

    inside the above function of course.

    0 讨论(0)
  • 2020-12-02 08:17

    iOS 11 no longer requires any hacks.

      override var hasFullAccess: Bool {
        if #available(iOS 11.0, *) {
          return super.hasFullAccess// super is UIInputViewController.
        }
        if #available(iOS 10.0, *) {
          let original: String? = UIPasteboard.general.string
          UIPasteboard.general.string = " "
          let val: Bool = UIPasteboard.general.hasStrings
          if let str = original {
            UIPasteboard.general.string = str
          }
          return val
        }
        return UIPasteboard.general.isKind(of: UIPasteboard.self)
      }
    
    0 讨论(0)
提交回复
热议问题