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 file created by NSUserDafults to store the app's preferences.
I would like to have the option of keeping my app's preferences file in sync between two different devices (an iPad and an iPhone, for example). Is this an acceptable use of iCloud syncing? Or would I need to convert the plist file into a different type of document, store it on the cloud, and convert it back into the app's preferences file upon retrieving it?
thanks!
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.)
There is a library available to do this with one line of code
https://github.com/MugunthKumar/MKiCloudSync
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With