NSUbiquitousKeyValueStore shared between Apple Watch and iPhone app

Hello,

Ive found in watchOS 9 NSUbiquitousKeyValueStore is available and I'm wondering if using the same cloud kit container should the value be the same across devices. It currently works between Mac and iPhone apps, but not between Watch and iPhone.

I have a switch on Apple Watch

if #available(watchOS 9.0, *) {
    Toggle("Use iCloud", isOn: $dontUseiCloud)
        .onChange(of: dontUseiCloud) { value in
            changeiCloudSetting(value)
             print("Toggle value = \(value)")
             print("Dont use icloud =  \(NSUbiquitousKeyValueStore.default.bool(forKey: "dontUseICloud"))")
          }
     }
}.onAppear(perform: {if #available(watchOS 9.0, *) {isiCloudOn()}})

and when I toggle the switch the Key-Value store changes correctly but only for the Watch. The switch on the iPhone app docent change, even if I wait up to 5 minutes.

I have the same code in my iPhone app and Mac app and the switch change happens almost immediacy through iCloud on both devices. Thanks

Answered by Frameworks Engineer in 729091022

Check to make sure that the iCloud Key-Value Service entitlement is the same across all platforms (on watchOS it may have been set to $(TeamIdentifierPrefix)<APP_BUNDLE_IDENTIFIER>.watchkitapp by default, and you really need it to be $(TeamIdentifierPrefix)<APP_BUNDLE_IDENTIFIER>). Let us know if that doesn't do the trick.

Accepted Answer

Check to make sure that the iCloud Key-Value Service entitlement is the same across all platforms (on watchOS it may have been set to $(TeamIdentifierPrefix)<APP_BUNDLE_IDENTIFIER>.watchkitapp by default, and you really need it to be $(TeamIdentifierPrefix)<APP_BUNDLE_IDENTIFIER>). Let us know if that doesn't do the trick.

NSUbiquitousKeyValueStore shared between Apple Watch and iPhone app
 
 
Q