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

醉酒当歌 提交于 2019-11-30 07:49:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!