iCloud key value storage sharing for iOS and mac os

I am working on an app that I would like to release for both mac and iOS. I'd like to use iCloud Key Value storage to share small bits of data between the apps. Unfortunately, it appears that the iOS and mac apps are writing to different iCloud KVS container IDs.


per https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html#//apple_ref/doc/uid/TP40012582-CH26-SW2


> Configuring Key-Value Storage

> Key-value storage allows an app to share small amounts of data with other instances of itself running on the user’s other devices. The container ID for key-

value storage is

iCloud.[$(TeamIdentifierPrefix)].[$(CFBundleIdentifier)]
where the Team ID is a unique string assigned to your team. To enable key-value storage, select the “Key-value storage” checkbox. To learn how to use key-value storage for preferences, read iCloud Design Guide.


So, assuming my team identifier is JaysTeam and my iOS app's CFBundleIdentifier is com.jay.sampleapp, then the container ID for my iOS app would be "JaysTeam.com.jay.sampleapp"


Unfortunately, I cannot set the CFBundleIdentifier of both targets to the same value. So it appears that I cannot get both an iOS and a mac app to write to the same iCloud Key Value Storage container. Thus, I can't share info between an iOS and a Mac app via iCloud Key Value Storage.


Am I missing something, or is this correct?

hey, we are able to do mac/ios icloud sync with key value pairs so you must have something messed up in the app id or maybe one is using

a devel cloud and one not? but our mac app and ios app are built in separate xcode projects, so maybe that is this sticking point if it wont let you set

both targets to the same cloud location


one thing we are running into is that key-value storage sync seems to be a) glitchy, or b) troublesome if users don't log in properly (the same) on all of their devices. we get cases where users complain that they are not getting data transferred thru icloud (intermittently, sometimes it works, sometimes it doesnt).


and it is difficult to debug since we havent yet found a way to view the user's icloud data directly (e.g on the server)


so where is it failing? upload, download, bug in the app code? who knows! since it works Most of the time, how to fix these problems and properly support the users? we dont know yet...

Late to the game but the solution is here:

https://developer.apple.com/documentation/foundation/icloud/synchronizing_app_preferences_with_icloud?language=objc


For each target (iOS and macOS):

In the Xcode project, open the target’s PrefsInCloud.entitlements file.

In that file, go to com.apple.developer.ubiquity-kvstore-identifier entitlement and replace $(CFBundleIdenfier) with your key-value >store ID (i.e. $(TeamIdentifierPrefix)<your key-value_store ID>).
For example if your key-value store ID is “com.mycompany.myKeyValueStoreID” it would look like this: 

$(TeamIdentifierPrefix)com.mycompany.myKeyValueStoreID.

It’s important that the key-value store ID portions are the same between both targets.






iCloud key value storage sharing for iOS and mac os
 
 
Q