3
votes

I'm using the NSUbiquitousKeyValueStore to store data to iCloud from an iOS app A but I can't get any object on my iOS app B. However I can get the object on my iOS app A. Both apps have the same team ID and both have the same Ubiquity Container Identifiers. I have added the iCloud capability thru XCode 5, which created automatically the entitlements files. I've also turned the iCloud option on for both App IDs.

Here is how I set data from App A:

[[NSUbiquitousKeyValueStore defaultStore] setObject:value forKey:key];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];

Here is how I get data on App B:

[[NSUbiquitousKeyValueStore defaultStore] synchronize];
[[NSUbiquitousKeyValueStore defaultStore] objectForKey:key];

I don't know if that matters but I am running both apps in Debug mode. Do I have to create both Apps on iTunes with iCloud enabled?

Thanks!

3
I don't have any experience with key value store, so I probably should not comment, but I did notice that there doesn't seem to be anywhere to enter a shared identifier for the KV store. If your apps have different bundle ids, how are they sharing the same KV store? - Drew McCormack
Drew thank you for your comment, it didn't have the answer but it helped me finding a way to solve this problem. - user991771

3 Answers

13
votes

Solved it! So to share Key Value Store between two different apps with the same Team ID I had to change the iCloud Key-Value Store in the entitlements file to be the same in both apps. By default the value is $(TeamIdentifierPrefix)$(CFBundleIdentifier) and I changed it to be $(TeamIdentifierPrefix)my.company.AppA.

Hope it helps someone =)

4
votes

Here's link to documentation. Look for "Configuring Common Key-Value Storage for Multiple Apps"

0
votes

Idk if this is a new thing in Xcode 9, but if you go to the Capabilities tab and after you turn on iCloud there, you can pick a container or create one. If all of your apps have the same container as specified here, you can back up your data via file system or Core Data and they can all access the same data in iCloud. I know this is 100% true because I have done it and it works really well.