How to use NSUbiquitousKeyValueStore and NSUserDefaults together

后端 未结 3 887
太阳男子
太阳男子 2021-01-12 04:36

Documentation is not clear on how to use NSUbiquitousKeyValueStore with edge cases.

If I want to set a value, I understand that I should set a value to

3条回答
  •  抹茶落季
    2021-01-12 04:56

    I am using http://blog.mugunthkumar.com/coding/ios-code-mkicloudsync-sync-your-nsuserdefaults-to-icloud-with-a-single-line-of-code/

    It is a simple class written by Mugunth Kumar (thanx !) that does the work for you... Unless you have special needs, add one line of code and it will do all the reading and writing to iCloud... all you need to do is read and write to NSUserDefaults as usual...

    Edit:

    Carful, if you remove an item from NSUserDefaults the code I linked to above will not remove the item from the cloud. Whenever you remove an item from NSUSerDefaults please do the same to NSUbiquitousKeyValueStore as So:

    NSUbiquitousKeyValueStore* keyValueStore=[NSUbiquitousKeyValueStore defaultStore];
    [keyValueStore removeObjectForKey: yourKey];
    

提交回复
热议问题