You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 13:03:19