使用Core Data,iCloud和CloudKit进行同步和备份,以及它们如何协同工作 [英] Using Core Data, iCloud and CloudKit for syncing and backup and how it works together

查看:2321
本文介绍了使用Core Data,iCloud和CloudKit进行同步和备份,以及它们如何协同工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于建立应用程式的初期阶段,我想储存,同步处理和备份资料。应用程序不会将任何文件存储在数据库中。它将是iOS 8及以上,所以我可以使用CloudKit。我做了一些研究,仍然不清楚如何核心数据,iCloud和CloudKit协同工作。



据了解,CloudKit只是一种从云端获取和检索数据的方式。 CloudKit只是与iCloud同步数据的不同方式?



我的问题是:


  1. 如果我使用CloudKit,还需要创建本地核心数据库吗?




    • 如果是,自动与iCloud同步,或者我必须调用方法才能存储到这两个地方?


  2. 当iOS设备未连接到互联网时,云用户将能够访问它。我读到CloudKit只有有限的缓存。


  3. 如果iCloud帐户未启用,如何工作。

如果有人可以分解每项技术在离线和在线保存和同步核心数据数据的过程中所做的工作。 p>

我目前的理解是:




  • 核心数据用于存储数据


  • CloudKit提供的功能




我希望我为这个问题提供了足够的信息,

解决方案

如下:




    <
  • 核心数据启用iCloud 会启用同步功能iCloud。您在Core Data中保存的任何更改都会传播到云,并且会自动下载云中所做的任何更改。数据存储在iCloud和本地持久存储文件中,因此即使设备处于离线状态也可以使用。您不必编写任何特定于云的代码,您只需要添加监听传入的更改(这很像在不同的受管对象上下文中所做的更改)。

  • CloudKit与Core Data无关。它不是同步系统,它是一个传输系统。意思是任何时候你想要读/写云数据,你需要进行显式CloudKit API调用这样做。没有任何事情自动发生。 CloudKit不会在设备上存储数据,因此,如果设备处于离线状态,则数据不可用。 CloudKit还使用iCloud添加了一些不适用于Core Data的功能,例如公共共享数据,以及仅下载部分数据集而不是整个数据集的功能。



如果您想将CoreKit与Core Data结合使用,您必须编写自己的自定义代码,以在受管对象和CloudKit记录之间进行转换。这不是不可能,但它是更多的代码写。

可能更可靠,但现在说的太早了。



我写了博客文章从过去使用Core Data和iCloud的人的角度来描述CloudKit。



更新,2016年6月:自最新的 NSPersistentStoreCoordinator ,与Core Data with iCloud相关的所有内容都标记为已弃用。因此,应该避免新的开发。


I am in the early stages of creating an app where I would like to save, sync and backup data. The app will not store any files just data in a database. It is going to be iOS 8 and up so I am able to use CloudKit. I did some research and still not clear on how Core Data, iCloud and CloudKit work together.

As far as understand CloudKit is just a way of getting and retrieving data to/from the cloud. Is CloudKit just a different way of syncing data with iCloud?

My questions are:

  1. If I do use CloudKit, do I still need to create local core data database?

    • If yes will it be automatically synced with iCloud or I would have to call methods to store to both places?
  2. If the data is only stored in the cloud will user be able to access it when iOS device is not connected to the internet. I read that CloudKit will have only limited caching.

  3. How will that work if iCloud account is not enabled.

If someone can kind of break down what each technology does in the process of saving and syncing core data database offline and online.

My current understanding is:

  • Core Data is used to store data locally

  • iCloud syncs the data and stores in the cloud

  • CloudKit gives the ability to store and manage data in the cloud??

I hope I provided enough info for this question not to get closed.

解决方案

It's like this:

  • Core Data on its own, is completely local and does not automatically work with any of Apple's cloud services.
  • Core Data with iCloud enabled turns on syncing via iCloud. Any changes you save in Core Data are propagated to the cloud, and any changes made in the cloud are automatically downloaded. The data is stored both in iCloud and in a local persistent store file, so it's available even when the device is offline. You don't have to write any cloud-specific code, you just need to add listening for incoming changes (which is a lot like changes made on a different managed object context).
  • CloudKit is not related to Core Data. It's not a sync system, it's a transfer system. Meaning that any time you want to read/write cloud data, you need to make explicit CloudKit API calls to do so. Nothing happens automatically. CloudKit does not store data on the device, so the data is not available if the device is offline. CloudKit also adds some features not available to Core Data with iCloud-- like public shared data and the ability to download only part of the data set instead of the whole thing.

If you wanted to use CloudKit with Core Data, you'd have to write your own custom code to translate between managed objects and CloudKit records. It's not impossible, but it's more code to write. It might be more reliable but it's too soon to say for sure.

I wrote a blog post describing CloudKit from the perspective of someone who's used Core Data and iCloud in the past.

Update, June 2016: As of the most recent documentation for NSPersistentStoreCoordinator, everything related to Core Data with iCloud is marked as deprecated. As a result it should probably be avoided for new development.

这篇关于使用Core Data,iCloud和CloudKit进行同步和备份,以及它们如何协同工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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