How to integrate iCloud on a non Document-based app?

I’ve read the Apple docs and Ray Wenderlich’s tutorial. It seems that I’m forced to use UIDocument so I read it up in the docs. I’ve found that it’s effective to use Document-based approach.

My problem is I don’t want to be tied in techniques specific to the platform (iOS) thus my app has its own models made from scratch that only inherit from NSObject. This includes saving/loading.

  • iOS 9 CoreData / ICloud - No such document at URL
  • iCloud: can I ignore those who disable iCloud?
  • 1st april dates of 80s failed to parse in iOS 10.0
  • Syncing a local sqlite file to iCloud
  • iCloud Key-Value-Store Synchronization issues (NSUbiquitousKeyValueStoreDidChangeExternallyNotification not called)
  • How can I migrate the data from the iCloud store file to a new store file in local storage?
  • Now, I need to integrate iCloud along with my old models. How will I do it in an elegant/effective way where I get to keep my old model implementation and be able to integrate iCloud?

    Solutions Collect From Internet About “How to integrate iCloud on a non Document-based app?”

    You are not in any way forced to use UIDocument. You can use iCloud via NSFileManager and NSMetadataQuery. The general approach is:

    When creating files

    • Create the file locally, as normal without iCloud
    • Use -[NSFileManager setUbiquitous:itemAtURL:destinationURL:error:] to transfer the file to iCloud storage.
    • (if necessary) Check on upload progress using NSMetadataQuery or by polling URL resource values.

    When opening files

    • Use NSMetadataQuery to locate iCloud-resident files
    • Use -[NSFileManager startDownloadingUbiquitousItemAtURL:error:] to begin download or to synchronize the local copy with the cloud copy.
    • Check on upload progress using NSMetadataQuery or by polling URL resource values with [NSURL resourceValuesForKeys:].

    When editing files

    • Use NSFileCoordinator to coordinate your file access with the ubiquity daemon.
    • Use NSFilePresenter to get notifications of changes to files.

    This is all covered in sessions from WWDC 2012 (and maybe 2011, I don’t recall), and the classes and methods you’ll need are all in the iOS documentation.