Search code examples
iosobjective-cios8icloudkey-value-store

Detect iCloud account availibility / change using Key-Value store only?


I use iCloud Key-Value store, without any container (as I don't need documents).

So the app is not listed in Settings / iCloud / Storage / Manage Storage list, only in iCloud / iCloud Drive list, like this:

enter image description here

I really want to know somehow if it is turned ON or OFF, or available at all.

Seems ubiquityIdentityToken is always nil, and NSUbiquityIdentityDidChangeNotification never gets called.


I have a working prototype, modifiy a slider in simulator, it gets updated on the device, everything seems fine. Even though, if I ask for the identifiers (in the NSUbiquitousKeyValueStoreDidChangeExternallyNotification callback), they're always null:

NSURL *containerURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
id token = [[NSFileManager defaultManager] ubiquityIdentityToken];
NSLog(@"containerURL: %@", containerURL);
NSLog(@"token: %@", token);

// containerURL: (null)
// token: (null)

When I turn off iCloud Drive for my app, it gets terminated in the background. No any notification gets called, nor at relaunch.

Should I simply setup a Document container I never use?


Solution

  • Having iCloud Documents turned on, I have the token (app entitlements get some new values as well).

    But the ubiquityIdentityToken now returns value even if I turn iCloud Drive OFF (!) in device settings for the given app. It does not pulls updates from the Key-Value store, still the token is set.

    Only URLForUbiquityContainerIdentifier returns nil when turned OFF, and the URL when turned ON.