Search code examples
iosobjective-cdictionaryicloud

Send Dictionary to iCloud using Key-value


I am using this code for writing a dictionary to iCloud.

 [[NSUbiquitousKeyValueStore defaultStore]
     setDictionary:dictCloudTables forKey:@"Tables"];

 [[NSUbiquitousKeyValueStore defaultStore] synchronize];

And i am fetching dictionary from cloud using this code:

 dictCloudTables = [[[NSUbiquitousKeyValueStore defaultStore]
                      dictionaryForKey:@"Tables"] mutableCopy];

It always gives me dictionary that i have inserted for the very first time.

Is there anything wrong with my code?


Solution

  • I don't see anything obviously wrong with the code (except you don't check the return value of synchronise). I think what might be wrong is your expectation of what should happen. Here's an extract from the documentation:

    This method does not force new keys and values to be written to iCloud. Rather, it lets iCloud know that new keys and values are available to be uploaded. Do not rely on your keys and values being available on other devices immediately.