NSUbiquitousKeyValueStore vs. NSUserDefaults

From Apple Documentation NSUbiquitousKeyValueStore :

If you write a key value persistence object when the user is not signed into an iCloud account, the data is saved locally until the next sync opportunity. When a user signs up for an iCloud account, the system automatically checks your local, disk-based keys and values ​​against the data on the iCloud server.

Therefore, if the user never signs up for an iCloud account, the key value persistence object is stored locally indefinitely, similar to NSUserDefaults.

In this case, should we stop using NSUserDefaults and just use NSUbiquitousKeyValueStore as the "default" for all applications? What are the disadvantages of this approach?

The advantage I see is that from a user perspective, app preferences will be synced across all their devices, which is more likely to be more user-friendly!

+3


source to share


2 answers


We must clearly understand that NSUbiquitousKeyValueStore

iCloud is designed to customize and track the state of the application across all devices of a specific account.

Some facts: fight NSUbiquitousKeyValueStore

.

In the documentation, we can find that:



Avoid using this class for data that your applications need. offline behavior; instead, store such data directly in the default local user database.

Also, the size of the data that can be saved is relatively small.

The total amount of space available in the app key store for this user is 1 MB. There is a limit on the key size for 1 key, and no more than 1024 keys.

0


source


I found that the user goes to their iCloud settings and turns off the app. You can no longer save NSUbiquitousKeyValueStore.

Your app will start by activating it. Then you can save the data there. When iCloud is turned off, it will always be readable, but if you refresh the data and restart the app, I trust that you will be back to what it was before the user turned off iCloud support in iCloud settings.

This is the problem I am currently working with. I am trying to find a way to check if this switch is on and change the datastore to NSUserDefaults.

Correct me if I am wrong, but this is what I have discovered so far.



-Mark

edit: this is only if you signed up for iCloud documents. If you only use NSUbiquitousKeyValueStore, it should be pretty much the same as I imagine.

edit-edit: now its action is different. The switch exists when ONLY the NSUbiquitousKeyValueStore is validated against iCloud capabilities. So, look - again - to determine if this switch is toggled for an app in the iCloud settings.

0


source







All Articles