I've seen all the other posts of SO about sharing NSUserDefaults data between host apps and app extensions, but mine still doesn't work. Here's everything I've done:
- Enable App Groups on Xcode's "Capabilities" tab for the extension and host app.
- Set the group name to "group.com.mycompany.foo" and confirmed the extension and host app are added to the group.
- Confirmed an entitlements file exists for both with the "com.apple.security.application-groups" key set to my app group name. (For what it's worth, I'm also using the shared keychain capabilities between extension and host app and that is working -- so I don't believe this is an issue with entitlements)
- Regenerated all provisioning profiles. In fact, I even revoked all my certificates and regenerated all profiles fresh after setting up the app group.
And after all of that, this code still doesn't work:
// in the host app
NSUserDefaults *testDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.mycompany.foo"];
[testDefaults setObject:@"TEST" forKey:@"foo"];
[testDefaults synchronize];
and then:
// in the extension
NSUserDefaults *testDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.mycompany.foo"];
NSLog(@"%@", [testDefaults objectForKey:@"foo"]);
which results in:
(null)
When I look in Xcode preferences, I notice these icons, none of which have the "App Group" icon:
But as I stated before, I went as far as clearing out my keychain, certs, and provisioning profiles after setting up the app group. So if this is in fact the problem, how do I add the entitlement to the profiles?
What am I missing? I'm fresh out of ideas.
Help?
EDIT: Access groups are working in my Today & Safari extension, just not in the WatchKit extension. I have no idea why, and all the build settings appear to be configured the same way.
EDIT 2: For those insisting that my capabilities aren't setup properly, here's a screenshot:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…