简体   繁体   中英

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.

Lets say I got an iPhone and I've been using my app for a while and theres lots of local data. Then I get an iPad and starts to use the app with iCloud (a switch to enable 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?"

So, how can i see if there´s already data on 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. Then you would add an observer to NSPersistentStoreDidImportUbiquitousContentChangesNotification for your app to be able to react to changes to the store.

So, basically, the NSPersistentStoreDidImportUbiquitousContentChangesNotification observer is the place where you know that data is available/changed.

If your store is of the atomic type, you would instead use the NSFilePresenter protocol to get notifications inside of your apps.

You might find interesting giving a look at Using Core Data with iCloud Programming Notes .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM