Can I use iCloud to sync the NSUserDefaults plist file

后端 未结 3 1485
鱼传尺愫
鱼传尺愫 2020-12-05 11:16

I was wondering if it was possible to use iCloud to sync an app\'s preferences file between devices. The preference file I am talking about is the com.domain.appname.plist f

相关标签:
3条回答
  • 2020-12-05 11:49

    Similar to MKiCloudSync, I also have a library on GitHub called SDCloudDefaults. Rather than sync automatically, there's a new object that you use instead of NSUserDefaults that saves to both iCloud and NSUserDefaults. This means you can decide which elements are stored locally and which are stored in the cloud.

    (I found MKiCloudSync after I'd implemented it. I think it's clever but I don't want to sync everything to iCloud so my solution still works better for me.)

    0 讨论(0)
  • 2020-12-05 11:58

    There is a library available to do this with one line of code

    https://github.com/MugunthKumar/MKiCloudSync

    0 讨论(0)
  • 2020-12-05 11:59

    It is possible to sync preferences between devices using iCloud. However, I would recommend against sharing the plist file between devices.

    The NSUbiquitousKeyValueStore should be suitable for what you trying to do. It is very similar to NSUserDefaults, so it should be easy to pick up.

    To use it, simply enable the com.apple.developer.ubiquity-kvstore-identifier entitlement in your entitlements file and just duplicate the preferences you like to sync in the ubiquitous key value store. Once it's in the ubiquitous kvstore, you'll be able to see it from the application on other devices. You can even sync between different applications as long as they use the same identifier.

    You should also register for the NSUbiquitousKeyValueStoreDidChangeExternallyNotification notification to watch for new changes and update the standardUserDefaults on the device accordingly.

    0 讨论(0)
提交回复
热议问题