NSUbiquitousKeyValueStore not syncing with iCloud

I tried everything and read all topics, but I can’t find out why NSUbiquitousKeyValueStore is not stored in iCloud.

• Created a specific application identifier

• Included iCloud in this app id

• Provisioning profile created

• Enable iCloud in the project

• Set the rights to the key value: $ (TeamIdentifierPrefix) $ (CFBundleIdentifier)

• Enabled iCloud Drive on the device

But NSUbiquitousKeyValueStore only stores locally. When I reinstall the application, it does not receive information from iCloud.

This is how I try:

NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore]; if ([[cloudStore stringForKey:@"testString"] length] == 0) { NSLog(@"Nothing in iCloud - setting a value..."); [cloudStore setString:@"I'm live in iCloud!" forKey:@"testString"]; [cloudStore synchronize]; [[NSUbiquitousKeyValueStore defaultStore] synchronize]; } else { NSString *result = [cloudStore stringForKey:@"testString"]; NSLog(@"Found something in iCloud - here it is: %@", result); } [self registerForiCloudNotificatons]; 

If I delete the application or try on the new device, it will not find anything in iCloud.

So, I tried this to find out if iCloud works:

  NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; if (ubiq) { NSLog(@"iCloud at %@", ubiq); } else { NSLog(@"No iCloud access, %@", ubiq); } 

And this always returns “no iCloud access”, and I can’t understand why. No matter what I do, the URLForUbiquityContainerIdentifier always returns zero.

I work on iOS 8 devices with iCloud enabled.

Did I miss something?

Thanks!

+5
source share
2 answers

I had the same problem. Logging out and back to my iCloud account on the device allowed it for me too.

This problem appears when you installed the application with the same package ID on the device before you allowed iCloud rights. I had this problem on two test devices. The third device on which I installed the application for the first time with iCloud turned on did not create problems.

+3
source

I had the same problem, thanks to this answer I was able to find out, however, all I did was delete the application → restart the device → install the application, and not log in and out of iCloud.

0
source

Source: https://habr.com/ru/post/1204930/


All Articles