Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting folders with UIDocumentBrowserViewController

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"])
like image 534
William Taylor Avatar asked Mar 04 '23 08:03

William Taylor


1 Answers

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.

like image 92
Nickkk Avatar answered Mar 18 '23 04:03

Nickkk