Key Data Not Storing to Icloud with Nsubiquitouskeyvaluestore.Defaultstore

NSUbiquitousKeyValueStore not syncing with iCloud

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.

iCloud NSUbiquitousKeyValueStore initial sync/access delay - how to handle?

Conclusion

Temporary solution is:
- call synchronize before get data from key-value store
- to be sure it would work "turn off iCloud->Documents&Data - turn off and again on network - turn on Documents&Data", but also you should wait several minutes before iCloud downloads all needed data

Note: when app is installed and already worked (saved/loaded) with key-value store updates of iCloud data are pretty fast (7-15 sec), but when you reinstall the app it seems that icloud needs several minutes to actualize key-value store.

I'd be glad to hear your thoughts, because icloud looks like almost unusable feature. But I don't want to set up my own server to merely get the same functionality.

iCloud Key Value Storage Changes Not Called (NSUbiquitousKeyValueStoreDidChangeExternallyNotification)

By signing out of iCloud accounts and back in all started working correctly

iCloud KeyValue store not recognized on first launch

When you first run an iCloud enabled App it has to pull all the data from Apple servers. The time it takes to do so depends on many things like what kind of network you're currently on (Edge, 3G, GPRS, WLAN). It also depends on how much traffic the iCloud server currently has to handle so the request to the iCloud server may take a few more seconds, no matter what type of network connectivity you have.

To sum it up: Yes, it sounds absolutely normal.

If running your App depends on those settings consider implementing a "Wait" or "Loading" view that stays on the screen as long as it takes for the App to perform a initial synch and load all needed data from the cloud. To not block the UI forever also implement a timeout for this view (if iCloud data not loaded within X seconds, dismiss the view and notify user).

App crash using iCloud Key-Value storage writing

setValue:forKey: is not a method on NSUbiquitousKeyValueStore.defaultStore() used to save data to an iCloud key-value store. Instead, it is the method from the NSKeyValueCoding protocol that is used for more general key-value coding with the types NSValue and NSNumber. The error you received refers to you attempting to access the “experience” key on your iCloudStore object itself rather than in the iCloud key-value store.

The methods available on NSUbiquitousKeyValueStore.defaultStore() to save key-value pairs are:

  • setArray:forKey:
  • setBool:forKey:
  • setData:forKey:
  • setDictionary:forKey:
  • setDouble:forKey:
  • setLongLong:forKey:
  • setObject:forKey:
  • setString:forKey:

Choose the method that best fits your type.

iCloud: NSUbiquitousKeyValueStore issue

You are attempting to retrieve data from iCloud when it is not downloaded yet. The downloading operation takes some time and you should register for NSUbiquitousKeyValueStoreDidChangeExternallyNotification to be able to access fresh data from iCloud. Here is a sample code:

- (void) registerForiCloudNotificatons
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleChangesFromiCloud:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:[NSUbiquitousKeyValueStore defaultStore]];
}

- (void) handleChangesFromiCloud: (NSNotification *) notification
{
NSDictionary * userInfo = [notification userInfo];
NSInteger reason = [[userInfo objectForKey:NSUbiquitousKeyValueStoreChangeReasonKey] integerValue];
// 4 reasons:
switch (reason) {
case NSUbiquitousKeyValueStoreServerChange:
// Updated values
break;
case NSUbiquitousKeyValueStoreInitialSyncChange:
// First launch
break;
case NSUbiquitousKeyValueStoreQuotaViolationChange:
// No free space
break;
case NSUbiquitousKeyValueStoreAccountChange:
// iCloud accound changed
break;
default:
break;
}

NSArray * keys = [userInfo objectForKey:NSUbiquitousKeyValueStoreChangedKeysKey];
for (NSString * key in keys)
{
NSLog(@"Value for key %@ changed", key);
}
}


Related Topics



Leave a reply



Submit