Search code examples
iosicloud-drive

iOS accessing root of iCloud Drive with FileManager


I'm basically doing variations on this:

let dir = fileManager.url(forUbiquityContainerIdentifier: nil)?
let files = try fileManager.contentsOfDirectory(at: dir)

trying to get to the root (i.e., the "/") of iCloud Drive, where I have some files that aren't in any folder.

However, dir is (expectedly, I guess) my app's folder.

Is it even possible to access the root of iCloud Drive? I mean, users can obviously drop files here, but can I get to that directory? (Note that for the moment I'm trying to avoid using a DocumentPickerViewController.)


Solution

  • It is not possible to access directly files outside of your app's iCloud container. I you want to allow users to give your app access to files that are potentially stored somewhere else, you need to UIDocumentPickerViewController.

    More information on iCloud documents can be found here: https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html#//apple_ref/doc/uid/TP40012094-CH2-SW1