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

icloud-drive, ios, swift

Solution

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

Problem

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

Original source

Related problems