Taking our Core Data and iCloud integration one step further we now demonstrate how an OS X app can be synchronised with an IOS app using Core Data and iCloud integration.
The video below shows the integration that can be achieved between OS X and iOS apps. Note that the iOS apps are the exact same apps shown in the other Core Data and iCloud Integration videos.
If there is enough interest I will post some of the OS X code, which uses NSPersistentDocument, used to share documents in iCloud, remove them from iCloud and to save local backup copies of iCloud documents.
Hi! How did you managed to use NSPersistentDocument with iCloud, while official documentation clearly states the opposite (no support at all)? Would you please share the sources (OS X version) or at least give some conceptual guiding? Thank you!
As the documentation says there is no iCloud support so you have to build your own. Given NSPersistentDocument is just a plain sqlite file (binary, xml or sqlite), this is not hard to do. Primarily it involves overriding this method
- (BOOL)configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:
and passing
NSPersistentStoreUbiquityNameKey
as a parameter if the store is iCloud enabled. However you still need to migrate files to and from iCloud using the usualmigratePersistentStore
methods. I’ll see if I can find some time to post an explanation and some of the code in the next few days.Thank you for your reply! Any chance of this also working with document being a package (accessible via NSFileWrapper)?
hi, I’m trying to add a switch to turn off/on iCloud from the App. Do you have a sample code to download?
Thanks
You can’t control the device global settings from within an app. All you can do is control the apps own use of iCloud.
True, nonetheless I still found a way to use a switch (flag) and use the fallback or Cloud storage depending on payment.