iCloud综述及背景:
请参照 iCloud(一)综述和iCloud(二)保存key value数据到iCloud。
什么时候该用Key-Value来存储?
You can set up Core Data to store its data on iCloud. If your app doesn’t have the concept of documents or files but has a large amount of data, this method is usually the best choice.
Each instance of your app, on each device attached to an iCloud account, maintains its own local Core Data store file. When data changes locally, Core Data writes change log files to your app’s default ubiquity container.
Early in your app’s life cycle, register for the NSPersistentStoreCoordinator notification NSPersistentStoreDidImportUbiquitousContentChangesNotification. When a Core Data store has imported changes from iCloud, it posts this notification. On receiving it, refresh the affected records and update the user interface.
使用Core Data来存储到iCloud的注意点:
-
Place your SQLite Core Data store within a <my_folder>.nosync subdirectory of one of your app’s ubiquity containers. This placement ensures that, if a user switches iCloud accounts, the system takes care of keeping each account’s data associated with the correct account.
-
Do not prepopulate the contents of a new SQLite store, such as to provide seed records the first time a user launches your app, by moving or copyin