[英]How can i see if my app got iCloud data?
I am integrating my core data app with iCloud and I want the user to be able to choose if they want to migrate the local data to iCloud or they can choose if they want to download data thats already on iCloud. 我正在将核心数据应用程序与iCloud集成在一起,我希望用户能够选择是否要将本地数据迁移到iCloud,或者他们可以选择是否要下载iCloud上已有的数据。
Lets say I got an iPhone and I've been using my app for a while and theres lots of local data. 可以说,我有一部iPhone,并且使用我的应用程序已有一段时间,并且本地数据很多。 Then I get an iPad and starts to use the app with iCloud (a switch to enable iCloud).
然后,我得到了一个iPad,并开始在iCloud中使用该应用程序(启用iCloud的开关)。 Now I want, on my iPhone, to include iCloud and I want to be prompted with a message: "Do you want to migrate your local data or download current data from iCloud?"
现在,我想在我的iPhone上包括iCloud,并希望得到一条消息提示:“您要迁移本地数据还是要从iCloud下载当前数据?”
So, how can i see if there´s already data on iCloud? 那么,如何查看iCloud上是否已有数据?
The general idea is that when you create a Core Data persistent store, you pass in a couple of parameters ( NSPersistentStoreUbiquitousContentNameKey
and optionally NSPersistentStoreUbiquitousContentURLKey
) to identify a metadata file which is stored in iCloud. 通常的想法是,当您创建Core Data持久存储时,您传入几个参数(
NSPersistentStoreUbiquitousContentNameKey
和可选的NSPersistentStoreUbiquitousContentURLKey
)来标识存储在iCloud中的元数据文件。 Then you would add an observer to NSPersistentStoreDidImportUbiquitousContentChangesNotification
for your app to be able to react to changes to the store. 然后,您可以向
NSPersistentStoreDidImportUbiquitousContentChangesNotification
添加观察者,以使您的应用程序能够对商店的更改做出反应。
So, basically, the NSPersistentStoreDidImportUbiquitousContentChangesNotification
observer is the place where you know that data is available/changed. 因此,基本上,
NSPersistentStoreDidImportUbiquitousContentChangesNotification
观察器是您知道数据可用/已更改的地方。
If your store is of the atomic type, you would instead use the NSFilePresenter
protocol to get notifications inside of your apps. 如果您的商店属于原子类型,则应改用
NSFilePresenter
协议在您的应用程序内部获取通知。
You might find interesting giving a look at Using Core Data with iCloud Programming Notes . 看一下将核心数据与iCloud编程说明一起使用,可能会发现有趣的事情。
If you are looking for code examples, instead of putting them here, I would suggest you to give a look at this tutorial , which covers everything you need in detail, including adding an iCloud ON/OFF switch. 如果您正在寻找代码示例,而不是将其放在此处,建议您看一下本教程 , 该教程涵盖了您所需的详细信息,包括添加iCloud ON / OFF开关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.