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

Bartłomiej Semańczyk picture Bartłomiej Semańczyk · Nov 24, 2015 · Viewed 18.8k times · Source

Is there a way to choose file from iCloud Drive similar way to UIImagePickerController()?

Answer

Bartłomiej Semańczyk picture Bartłomiej Semańczyk · Jan 13, 2016

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