Is the iCloud Key-value independent for each device?

Asked 2 years ago, Updated 2 years ago, 110 views

I am creating an app using iCloud with swift.

Save the characters entered in the Text Field named MyTextField to the iCloud key-value with the following code:

let vStore=NSUbiquitousKeyValueStore.default()
iflet str = MyTextField.text{
        vStore.set(str, forKey: "inputText")
        vStore.synchronize()
}

Also

to retrieve values from iCloud key-value
let vStore=NSUbiquitousKeyValueStore.default()
iflet str = vStore.string(forKey: "inputText") {
    print("\"(str))
}

I did it in .

I saved it in iCloud without any problems in one iPhone, and I was able to read the values.
However, I installed the same app on two different iPhones and tried using the same Apple ID.
The key-value saved by one side cannot be read when the other reads it.
They all seem to behave independently.

Is the Key-value independent even if they use the same Apple ID but have the same Apple ID?
Please let me know if you know.

swift iphone icloud

2022-09-30 21:24

1 Answers

The Entitlement Plist file must have the same iCloud container ID to share the NSUquitableKeyValueStore with multiple apps.

The Entitlement file is automatically created by Xcode and the application bundle ID is automatically configured.To share across multiple apps, change the value to match the ID of one of the apps.

For more information, see the Configuring Common Key-Value Storage for Multiple Apps section of the official document.

https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html#//apple_ref/doc/uid/TP40012094-CH6-SW26


2022-09-30 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.