我正在开发一个新应用,我希望用户能够从iCloud或外部驱动器中选择一个文件夹。如何允许他们使用UIDocumentBrowserViewController选择文件夹?
我尝试将allowedContentTypes设置为文件夹“public.directory”的UTI,但是文档浏览器不允许选择文件夹。
UIDocumentBrowserViewController(forOpeningFilesWithContentTypes: ["public.directory"])
最佳答案
这是iOS 13的official Apple solution:
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
documentPicker.delegate = self
documentPicker.directoryURL = startingDirectory
present(documentPicker, animated: true)
常量
kUTTypeFolder
来自import CoreServices
。