SwiftUI .fileImporter与UIDocumentPickerViewController无内容显示问题
SwiftUI 文件选择器无内容显示问题
使用SwiftUI的.fileImporter或UIDocumentPickerViewController时,选择器可正常弹出,但无法显示任何内容:Shared和Recent选项显示「内容不可用」,Browse选项显示「我的iPhone为空」。
代码实现
.fileImporter 代码
var body: some View { VStack { // ... }.padding(.horizontal, 25) .fileImporter(isPresented: $selectingFile, allowedContentTypes: [.item], onCompletion: { _ in }) }
UIDocumentPickerViewController 代码
struct ImportDocumentView: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> some UIViewController { let controller = UIDocumentPickerViewController(forOpeningContentTypes: [.item]) controller.allowsMultipleSelection = false return controller } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} }
已排查的可能问题
- UTType设置错误:尝试多种类型均无效
- 模拟器问题:无真机测试,需在模拟器中解决,未找到同类无内容显示案例
- 访问权限:理论上应能访问应用专属文件夹但未显示,尝试配置Info.plist的
NSFileProviderDomainAccess无效(可能配置有误)
内容的提问来源于stack exchange,提问作者Simon Lemcke
相关产品推荐
相关产品推荐

