34

Prior to iOS 8.3, the way to check whether "Allow Full Access" was granted to a keyboard extension was through the following code in the container app:

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

However, as comments on this popular SO answer thread point out, since iOS 8.3, an app can read from shared group containers even if full access is not granted, so the above code always returns true. However, write permission is granted only if "Allow Full Access" is turned on.

I have tried listing out all of the pasteboards based on Apple's docs on UIPasteboard, but it does not delineate which ones are accessible. Any insights on this is much appreciated.

Community
  • 1
  • 1
daspianist
  • 5,336
  • 8
  • 50
  • 94
  • General pasteboard should be accessible to all for read and/or write. Shared containers are a different thing. Are you trying to have an app write to pasteboard which can be used by keyboard? Can you explain the scenario you want to use it in? – Omar Jul 28 '15 at 10:28
  • Please take a look into this answer: [http://stackoverflow.com/a/26088674/3317354][1] [1]: http://stackoverflow.com/a/26088674/3317354 – teamnorge Jul 28 '15 at 13:52
  • Hi @Omar - yes, indeed I am trying test whether the shared container could be writable (granting "full access" on an iOS keyboard allows it to be writable and readable, so one can read data from the container app based on what's saved from the keyboard). Previously `generalPastboard` would have sufficed. – daspianist Jul 28 '15 at 15:14
  • Please see "By default, a keyboard has no network access and cannot share a container with its containing app. To enable these things, set the value of the RequestsOpenAccess Boolean key in the Info.plist file to YES." in https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html and the available options when it is set to On https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW3 – Omar Jul 28 '15 at 15:59
  • Thanks for the follow up @Omar. These options, such as `RequestOpenAccess` and the configuring the App Group has already been done in my project (based on the links that you provided). What I am asking is, once this is configured, how do I, via the containing app, detect whether the user has turned on sharing of data between the container and its containing app. I can then provide different functionalities depending on the user's action. – daspianist Jul 28 '15 at 16:02
  • Thanks for the link @teamnorge. I have tried the code but it still has not worked. – daspianist Jul 28 '15 at 16:03
  • Full Access is an atomic permission. It is either yes or no. If it is enabled you will have read and write permission. See link http://stackoverflow.com/questions/25472388/how-to-check-the-allow-full-access-is-enabled-in-ios-8. If you are trying to make it work in an app group then you can test it by explicitly testing access to the app's sandbox. Otherwise it would be a security concern. – Omar Jul 28 '15 at 18:03
  • @Omar if you see the linked SO question you supplied, it's the exact same one as I referenced in the body of my question. I have consulted that question, and the problem is that the answer no longer works since iOS 8.3, hence my asking the question here. In other words, how do I explicitly test access to the app's sandbox. – daspianist Jul 28 '15 at 18:06
  • I just confirmed that the code [UIPasteboard generalPasteboard] works on device and not on simulator(nil when no Full Access and not nil when Full Access is allowed). Can you try it on device. I am running iOS 8.3. – Omar Jul 28 '15 at 21:27
  • @Omar thanks for trying. I have tried it on a device running iOS 8.4, and unfortunately it is not working. The exact code are as you see above in the question body, and its ran when executing `viewWillAppear` – daspianist Jul 28 '15 at 21:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84513/discussion-between-omar-and-daspianist). – Omar Jul 28 '15 at 21:33
  • @daspianist did you solve your trouble? i'm looking for answer too – TomSawyer Feb 23 '16 at 04:35
  • @TomSawyer Just saw this Tom. Unfortunately no solution yet. – daspianist Apr 04 '16 at 16:02

2 Answers2

2

Here's my currently working / deployed implementation:

- (void)viewDidAppear:(BOOL)animated {
    NSLog(@"keyboard has full access? %@", ([self validateKeyboardHasFullAccess] ? @"YES" : @"NO"));
}

- (BOOL)validateKeyboardHasFullAccess {
    return !![UIPasteboard generalPasteboard];
}
Yup.
  • 1,883
  • 21
  • 18
  • Thanks for the input! This works great when checking full access from inside the keyboard, but I was wondering if there is also a way to do so from the container app. – daspianist Nov 22 '15 at 23:40
1

On iOS 8.4 the UIPasteboard.generalPasteboard() is nil if Full Access is not allowed. Try removing keyboard and container app + clean and build app, before testing again. Should work fine.

Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
Omar
  • 463
  • 3
  • 11