How to use NSUbiquitousKeyValueStore and NSUserDefaults together

微笑、不失礼 提交于 2019-12-01 03:55:42

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];

The Mugunth Kumar answer provided above works beautifully if you want to sync all of your NSUserDefaults!

However, it is an ALL or NOTHING approach. You can not pick or choose the defaults you wish to sync.

I found this Tutorial that may be of assistance if you are looking to be more picky.

I wrote a simple iOS category that can be used to save a value also into NSUbiquitousKeyValueStore while storing into NSUserDefalt.

hope this help: https://github.com/RiccardoPaolillo/NSUserDefault-iCloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!