How to Access Files in Icloud Drive from Within My iOS App

How to access files in iCloud Drive from within my iOS app?

You can present controller the following way:

import MobileCoreServices

let documentPickerController = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF), String(kUTTypeImage), String(kUTTypeMovie), String(kUTTypeVideo), String(kUTTypePlainText), String(kUTTypeMP3)], inMode: .Import)
documentPickerController.delegate = self
presentViewController(documentPickerController, animated: true, completion: nil)

In your delegate implement the method:

func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL)

Note that you don't need to set up iCloud Entitlement to use UIDocumentPickerViewController. Apple provides sample code that demonstrates how to use this controller here

Hide iCloud Documents

If you don't want to expose this data to the user what you need is to save it to the library directory. Please take some time and read File System Basics.

Use the Library subdirectories for any files you don’t want exposed to the user.

The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.



Related Topics



Leave a reply



Submit