Core Data iCloud Syncing

佐手、 提交于 2019-12-04 13:06:06

I've managed to get this working by following this tutorial:

http://corsarus.com/2015/using-core-data-in-ios-part-4-core-data-syncing-with-icloud/

To summarise the changes I needed to make to my existing Core Data app:

  • Change the store URL to a different name which does not conflict with the local store's URL
  • Include the cloudOptions dictionary when adding the persistent store
  • Register for notifications of NSPersistentStoreCoordinatorStoresWillChangeNotification, NSPersistentStoreCoordinatorStoresDidChangeNotification and NSPersistentStoreDidImportUbiquitousContentChangesNotification
  • Implement methods called by observing those notifications which save and reset the context, update the UI and merge incoming changes from iCloud respectively

Swapping between local and cloud storage will be less straightforward but I'm confident that I understand enough now to give this a try.

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