jec047
jec047

Reputation: 31

Trouble with UserDefaults(suitename:)

I'm writing an iOS app that includes a Messages extension. To share data between them I created an app group with a key similar to "group.com.myCompany.myApp". The app stores an array of strings using userDefaults.set(:forKey:). Then the app can fetch or modify the array, and the extension can fetch (but not modify) the array.

Both the app and the extension are accessing the UserDefaults using UserDefaults(suiteName:). Both the app and the extension are using the same value for the suite name.

The problem I'm having is that this works just fine in the simulator but on the phone the extension doesn't see the array of strings. I'm completely at a loss.

Upvotes: 0

Views: 702

Answers (1)

jec047
jec047

Reputation: 31

It's the entitlements!

Earlier, in response to a post that has since been deleted, I wrote "the entitlement files are correct as far as I can tell." When I wrote that a light bulb went off in my head: "The app group entitlement is missing, that's why it works in the simulator and not on the phone!"

I didn't realize that the entitlements have to be specified separately for Debug and Release builds, and I had not specified them for the Release build. Adding that took care of the problem.

Upvotes: 2

Related Questions