I'm developing a new app and I would like the user to be able to select a folder from iCloud or an external drive. How can I allow them to select a folder using a UIDocumentBrowserViewController?
I have tried setting the allowedContentTypes to the UTI of folders, 'public.directory', but the document browser doesn't allow folders to be selected.
UIDocumentBrowserViewController(forOpeningFilesWithContentTypes: ["public.directory"])
Here is an official Apple solution for iOS 13:
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
documentPicker.delegate = self
documentPicker.directoryURL = startingDirectory
present(documentPicker, animated: true)
The constant kUTTypeFolder
comes from import CoreServices
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With