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
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
}
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
}
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)
}
}