Share NSUbiquitousKeyValueStore between Watch app and iOS app

As NSUbiquitousKeyValueStore is now available on watchOS 9, I wanted to share values between the iPhone app and the watch app using the key value store. However, it seems that the watch app creates a separate store with its <app-identifier>.watchkitapp identifier, so data is not synced between both.

I tried chaning the iCloud Key-Value Store identifier in the watch app's entitlements file. But then signing the app will fail.

Is there any way to use NSUbiquitousKeyValueStore as a shared store between iPhone and Watch?

Answered by FredBChicago in 734138022

What worked for me is changing the "iCloudKey-Value Store" key in the iOS entitlements file to $(TeamIdentifierPrefix)$(CFBundleIdentifier).watchkitapp

The same key in the watchOS entitlements file of course should then be left unchanged as $(TeamIdentifierPrefix)$(CFBundleIdentifier)

No signing issues.

To share an NSUbiquitousKeyValueStore, the store ID can be any ID that is unique and has the team ID prefix. If your store ID does have the team ID prefix, and still triggers a code sign error, I suggest that you file a Developer Technical Support request https://developer.apple.com/support/technical/ to communicate with Apple's DTS team. If you do that, please provide a sample project with detailed steps to reproduce the issue.

Hi! Sorry this is biting you. I think the right thing to do here is to set your iCloud Key-Value Service entitlement to in all the places (you might need to request it on behalf of your iOS app, but it will work for your watchOS app).

Accepted Answer

What worked for me is changing the "iCloudKey-Value Store" key in the iOS entitlements file to $(TeamIdentifierPrefix)$(CFBundleIdentifier).watchkitapp

The same key in the watchOS entitlements file of course should then be left unchanged as $(TeamIdentifierPrefix)$(CFBundleIdentifier)

No signing issues.

Share NSUbiquitousKeyValueStore between Watch app and iOS app
 
 
Q