8

I'm having trouble to share data between iOS 8 extension and container app. I set up the group from develop portal and Xcode, and my entitlements plist both look like:

<dict>
    <key>com.apple.security.application-groups</key>
    <array>
        <string>my group id</string>
    </array>
</dict>

The suggested solution in apple document to use [[NSUserDefaults standardUserDefaults]

doesn't work for me.

I've tried the solution by @Santa Claus from this post Communicating and persisting data between apps with App Groups to use

[[NSUserDefaults alloc] initWithSuiteName:@"<group identifier>"];

Santa Claus's solution worked on simulator but not on my iPhone 4s, any ideas on how to make it work on real device? Or am I missing anything?

Some updates:

[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group id"];

function returns url, and both urls from container app and extension look the same, as "path /private/var/mobile/Containers/Shared/AppGroup/3DFB9750-A9F3-4C37-BC3C-0D5BF746B‌​233". I created a json file inside that folder from container app but extension can't find any file in the folder when I run on device. But in simulator it finds it well and everything works.

Community
  • 1
  • 1
woof
  • 1,288
  • 1
  • 11
  • 13
  • I can confirm [my solution](http://stackoverflow.com/a/24063144/2446155) works on devices as well. Try uninstalling your applications and re-install them. – Andrew Jun 05 '14 at 19:25
  • Thanks, I tried uninstalling, it still doesn't work on device.. – woof Jun 05 '14 at 20:04
  • Confirm your group id is typed exactly the same in both application entitlements and in the `NSUserDefaults` initialization – Andrew Jun 05 '14 at 21:22
  • They are all the same, no luck :( – woof Jun 05 '14 at 23:16
  • See if [the other solution to that question](http://stackoverflow.com/a/24028248/2446155) works. You don't have to use it, but it will reveal whether app groups are setup correctly. – Andrew Jun 05 '14 at 23:20
  • I tried to use NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group id"], i could get a valid NSURL from container app but, from the extension it always returns nil. Could you get same NSURL from app and extension? Maybe my group is not set up correctly. – woof Jun 06 '14 at 01:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55198/discussion-between-santa-claus-and-woof). – Andrew Jun 06 '14 at 13:23
  • possible duplicate of [Communicating between apps with App Groups](http://stackoverflow.com/questions/24015506/communicating-between-apps-with-app-groups) – Andrew Jun 09 '14 at 15:05
  • Did anyone ever find a guaranteed solution for getting this to work on an device? – Jack Robson Aug 11 '16 at 21:49
  • I am also facing this issue , I have some images in host app and trying to access in child(extension) app getting valid url but sometimes it fetch the image sometimes its not . please update if some one have paramagnet fix. – Pandey_Laxman Oct 20 '16 at 13:35

3 Answers3

20

My solution is edit the Info.plist of my custom keyboard:

NSExtension -> NSExtensionAttributes -> RequestsOpenAccess

Make it YES.

Then delete the keyboard in your device and re-add it. In your keyboard add page you will find a setting named "Allow Full Access", enable it and the keyboard will access the shared data.

heheBear
  • 236
  • 2
  • 6
  • working in simulator but same thing not working in device any idea why? – Nitin Gohel Oct 06 '14 at 10:22
  • nice!! it took me so long to find what it wasn't working... would you know of a way to detect the setting value from the extension? – dvkch Nov 10 '14 at 20:08
  • @heheBear this works for me on Simulator but not on real device any suggestion ? – MAC Nov 20 '14 at 07:55
  • in my case (Sharing extension) is not working, i have added it in plist but not show on real device ,only work on simulators – Ravi Ojha May 29 '15 at 09:38
2

For keyboard extension, make sure enable RequestsOpenAccess as heheBear's answer
and try remove and add back keyboard from Setting/Keyoboard occasionally
keyboard extension is not stable and performance is really bad since beta 4, include beta 5

Ethan Liu
  • 21
  • 1
  • 2
1

The problem only occurs for custom keyboard, and iOS8 beta 2 fixed the issue.

woof
  • 1,288
  • 1
  • 11
  • 13