3

I've seen a couple of questions on this, and tried all the answers provided, and this still isn't working for me.

I'm trying to share several small pieces of data (Strings and BOOLs) between my iPhone App and its WatchKit extension. (If it makes any difference, the info is being read by the GlanceController of the WK app)

Via the Developer site I created an App group (group.com.theYawns.Sorcerers-Apprentice). If I look at 'App IDs' there I appear to have two identical IDs for my app (com.theYawns.Sorcerers-Apprentice) plus one for the extension (com.theYawns.Sorcerers-Apprentice.watchkitextension). Each of these has 'App Group' enabled (for both Development and Distribution) and the app group is selected if I edit the App ID.

I've turned on 'App Groups' in capabilities for both the App and the Extension. A concern I have it that periodically -- several times a day but not every build -- if I go in and look at the Capabilities tab, I have a red exclamation point saying 'Add the App Groups' entitlement to your entitlements file. If I look at the entitlements file, the entitlement is there, and if I click 'Fix issue', the red exclamation point changes to a checkmark. But the fact this needs to be done multiple times per day concerns me that something is amiss.

I've refreshed my provisioning profiles under XCode preferences many times, and while I don't see an App Groups icon under entitlements, if I hover I do see app groups in the tooltip that pops up.

In both my app and extension, I get a reference to the user defaults via

NSUserDefaults *sharedAppDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.theYawns.Sorcerers-Apprentice"]; 

I've also tried adding a [sharedAppDefaults synchonize] after each write and before my WatchKit attempts to read, just in case things weren't being flushed out. (Didn't make any difference).

My WatchKit extension bundle id is different from my iPhone App bundle id, which is one of the answers I saw on a different thread.

I've also added an NSTimer to refresh the glance every 10 seconds, so if there was a timing issue with picking up the changes, I would expect it to resolve itself after an update cycle or two, but it does not.

Really stumped ... seems others have had their issue resolved by answers from the other threads but none have worked for me.

Other threads I've searched include:

Why won't app groups work inside my WatchKit extension?

https://stackoverflow.com/questions/27047455/how-to-shared-storage-between-app-and-extension-with-app-group-and-

WatchKit NSUserDefaults and NSKeyedUnarchiver issue

Community
  • 1
  • 1
Mike Yawn
  • 115
  • 1
  • 6

2 Answers2

2

OK, I found an answer in the Apple developer forums.

It appeared, from the XCode target 'Capabilities' tab, that I had all the correct entitlements set. And I could see the 'Entitlements' file in my project, open it, and see that it was set up correctly.

BUT -- if I looked under my App Target's 'Build Settings' tab, in the 'Code Signing' section, there was no entitlements file shown. (It all shows up correctly for the WatchKit Extension but not for the main iPhone app).

When I plugged in the name of my entitlements file under Code Signing, everything started to work.

This seems like a bug to me -- I don't believe the 'Capabilities' tab and the 'Build Settings' tab of the same target should ever be looking in different places for entitlements. But wanted to post the answer that worked for me here in case anyone else runs into this.

Summary: to make sure entitlements are correct, you have to see the switches set properly in Capabilities, AND you have to see the entitlements file referenced under Build Settings / Code Signing.

Mike Yawn
  • 115
  • 1
  • 6
0

You have to add the entitlement to your provisioning profile of app extension.To do this, Login to your developer account to add the entitlements, after this download the latest provisioning profile. To verify whether the app group has been enabled or not , open the downloaded provisioning profile in "TextEditor" and search for "app group". This will show you the result, if you have done it properly. Use these newly downloaded provisioning profiles ,and it will show you the check mark in capabilities.

Santhosh
  • 103
  • 8