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

前端 未结 1 2072
猫巷女王i
猫巷女王i 2020-12-30 16:11

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 Do

相关标签:
1条回答
  • 2020-12-30 16:45

    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.

    0 讨论(0)
提交回复
热议问题