简体   繁体   English

我如何查看我的应用程序是否有iCloud数据?

[英]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.

相关问题 如何在不将其备份到iCloud的情况下通过我的应用程序提供演示数据? - How can I provide demo data with my app without backing it up to iCloud? 如何确认已为我的应用程序启用了iCloud备份? - How can I confirm that iCloud Backup is enabled for my app? 如何为核心数据数据库启用iCloud同步? - How can I enable iCloud synchronization for my Core Data database? 我可以将应用程序的SQLite数据库备份到iCloud吗? - Can I back up my app's SQLite database to iCloud? 如何在应用程序处于后台时通过iCloud检查我的UIDocument是否已更新? - How can I check if my UIDocument has been updated via iCloud while the app was in the background? 如何在发布 IOS 之前查看我的应用页面? - How can I see my app page before publish for IOS? 如何从Xcode查看iOS应用程序中的数据? - How can I see data inside an iOS app from Xcode? 如何从核心数据数据库中删除iCloud同步 - How can I remove iCloud sync from core data database 如何在短信应用中看到我的应用程序在iphone中发送的消息? - How can I see in SMS app my messages sent from within my app in iphone? 当我的 UIViewController 在我的 Swift 应用程序中显示给用户时,如何检查它是否被查看? - How can I check if my UIViewController got viewed when it appears to the user in my Swift app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM