Search code examples
iosicloudnsubiquitouskeyvaluestore

NSUbiquitousKeyValueStore not syncing with iCloud


I've tried everything and read all topics, but I can't find out why NSUbiquitousKeyValueStore is not being stored on iCloud.

• Created a specific App ID

• Enabled iCloud to this App ID

• Created Provisioning Profile

• Enable iCloud on the Project

• Setup the entitlements to Key Value: $(TeamIdentifierPrefix)$(CFBundleIdentifier)

• Turned on iCloud Drive on the device

But NSUbiquitousKeyValueStore is only saving locally. When I reinstall the app it doesn't get info from iCloud.

This is how I'm trying:

    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 app or try on a new device it doesn't find anything on iCloud.

So I tried this to find out if iCloud is working:

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

} else {
    NSLog(@"No iCloud access, %@", ubiq);
}

And this always return "no iCloud access" and I can't figure it out why. No matter what I do URLForUbiquityContainerIdentifier always return nil.

I'm running on iOS 8 devices with iCloud enabled.

Am I missing something?

Thanks!


Solution

  • I had the same problem. Logging off and back on my iCloud account on the device solved it for me, too.

    This problem seems to appear when you have installed the app with the same bundle identifier on the device before you enabled iCloud entitlements. I had this problem on 2 testing devices. A third device on which i installed the app the first time with iCloud enabled, made no problems.