Question

When I sync the user data (if the user request) to iCloud (using NSUbiquitousKeyValueStore), it syncs correctly. However, when I use 2 different devices, with 2 different apple IDs I see the SAME data on both and I'm still able to sync across them. So multiple users see each others data.

Is there any way to make the syncing user specific or have I made a mistake somewhere?

Some code that I use:

NSUbiquitousKeyValueStore *icloudatas = [NSUbiquitousKeyValueStore defaultStore];

//save to iCloud
[icloudatas setString:[NSString stringWithFormat:@"%i",
[defaults integerForKey:@"lvl"]] forKey:@"lvl"];


//load from iCloud
[defaults setInteger:[[icloudatas stringForKey:@"lvl"] integerValue] forKey:@"lvl"];

[defaults syncronise];
[icloudatas synchronize];

Problem resolved:

I just changed my Apple ID int the App Store, I forgot to change in iCloud. That resolved my problem, everything is working properly.

Was it helpful?

Solution

You shouldn't be copying the details into NSUserDefaults inside the app. This is how you are mixing up details from different users. Just use NSUbiquitousKeyValueStore on its own.

Well, more realistically, you can copy data, but you shouldn't just always copy all data between both stores.

You should be observing NSUbiquityIdentityDidChangeNotification and NSUbiquitousKeyValueStoreDidChangeExternallyNotification and checking the reason for NSUbiquitousKeyValueStoreAccountChange (from NSUbiquitousKeyValueStoreChangeReasonKey). When you detect that the user account changed you need to 'reset' any local data either to default values or to cloud values (and prevent any update to cloud values before that happens).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top