核心数据iCloud同步 [英] Core Data iCloud Syncing

查看:83
本文介绍了核心数据iCloud同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Core Data实施为新应用程序的本地存储,现在希望启用iCloud跨设备同步。我一直在阅读文档和一些教程,但无法了解如何在本地存储和云存储之间进行切换,以及在启用云存储后如何从iCloud同步更改。有人会介意整个过程,以便我随后去研究每个阶段吗?

I have implemented Core Data as local storage for a new app and now want to enable iCloud synchronising across devices. I've been reading the documentation and some tutorials but can't get my head around how to switch between local and cloud storage, and how to synchronise changes from iCloud when cloud storage is enabled. Would somebody mind summarising the process so I can then go and research each stage? Thanks in advance!

推荐答案

我已经通过遵循本教程来使此工作正常进行:

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/

总结我需要对现有Core Data应用进行的更改:

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


  • 将商店URL更改为其他URL与本地商店的URL不冲突的名称

  • 添加持久性存储时包括cloudOptions字典

  • 注册NSPersistentStoreCoordinatorStoresWillChangeNotification,NSPersistentStoreCoordinatorStoresDidChangeNotification和NSPersistentStoreDidImsUsportUbiquitousContent通知的通知

  • 通过观察那些保存和重置上下文,更新UI并合并传入的通知的调用方法分别从iCloud更改

  • 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.

这篇关于核心数据iCloud同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆