问题描述
我遵循了https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories指令,如何打开UIDocumentPickerViewController。
// Create a document picker for directories.
let documentPicker =
UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String],in: .open)
documentPicker.delegate = self
// Present the document picker.
present(documentPicker,animated: true,completion: nil)
但是由于某些原因,用户无法在ios 12及更高版本上选择文件夹。对于ios 13,它工作得很好。我试图在Google上搜索答案,但所有解决方案都对我不起作用。
解决方法
好的,所以我发现在iOS 12及更高版本中选择文件夹不可用。它仅在iOS 13以后才可用,并且在WWDC的一次会议中进行了讨论。
iOS 13的新增功能,您的应用可以显示UIDocumentPickerViewController 让用户选择一个文件夹。 -https://asciiwwdc.com/2019/sessions/719
因此,我建议尝试使用其他解决方案。例如,在我的情况下,我需要用户选择文件夹以在其中保存一些文档。但是我发现UIActivityViewController甚至更适合我的需求。