My iOS 11 app works with cloud-based files using UIDocumentPickerViewController (in .open
mode). Once I have the URL, how can I get the name of the location (file provider) that stores the file? (such as "iCloud", "Dropbox", etc)
My best guess was URLResourceValues.ubiquitousItemContainerDisplayName
, but it seems to work only for iCloud.
Here's a test code:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else { return }
let isAccessible = url.startAccessingSecurityScopedResource()
let res = try! url.promisedItemResourceValues(forKeys: [.ubiquitousItemContainerDisplayNameKey])
print("Container name: \(res.ubiquitousItemContainerDisplayName)")
if isAccessible {
url.stopAccessingSecurityScopedResource()
}
}
For files picked from iCloud, it prints "iCloud Drive". But for Dropbox-based files the container name is nil
.
Am I missing something? Is there another way?