英文:
FileImporter / UIDocumentPickerViewController not showing contents
问题
Both the .fileImporter function (in SwiftUI) and the UIDocumentPickerViewController are shown as intended, but they do not show any contents.
Instead, it says: "Content not available" on the Shared and Recent Icons and "My iPhone is empty" on the Browse Icon.
How did I implement them?
.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) {}
}
What I thought could be the problems:
- Wrong UTType -> tried a load of different options there; none helped.
- Emulator Problem -> I don't have an iPhone to test this. I need to make it work in the emulator. Other people had problems with the emulator, but not showing any data was not one of them.
- Access Permissions -> In my understanding, I should at least have access to the app-specific folder, but even that is not showing. I also tried to set "NSFileProviderDomainAccess" in Info.plist, but that didn't work either. (I might have done something wrong in the process though)
英文:
Both the .fileImporter function (in SwiftUI) and the UIDocumentPickerViewController are shown as intended, but the do not show any contents.
Instead it says: "Content not available" on the Shared and Recent Icons and "My iPhone is empty" on the Browse Icon.
How did I implement them?
.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) {}
}
What I thought could be the problems:
- Wrong UTType -> tried a load of different options there; none helped.
- Emulator Problem -> I don't have an iPhone to test this. I need to make it work in the emulator. Other people had problems with the emulator, but not showing any data was not one of them.
- Access Permissions -> In my understanding I should at least have access to the app specific folder, but even that is not showing. I also tried to set "NSFileProviderDomainAccess" in Info.plist, but that didn't work either. (I might have done something wrong in the process though)
答案1
得分: 0
I found the answer to my own question:
我找到了答案:
I had to "import UniformTypeIdentifiers"
我必须“导入UniformTypeIdentifiers”
Xcode doesn't complain about not having it, it just doesn't show any files or folders. Only indicator was a different color for the element in the allowedContentTypes: [] collection.
Xcode不会因为没有它而抱怨,只是不显示任何文件或文件夹。唯一的指示是allowedContentTypes: []集合中元素的不同颜色。
Edit: For those still not seeing much: the Xcode iPhone Simulator doesn't have any example/inital files or folders in there. I'd recommend to create a folder with the files app on the phone to see some feedback. If you want files in there use Swift's fileExporter.
编辑:对于仍然看不到太多的人:Xcode iPhone模拟器里没有任何示例/初始文件或文件夹。我建议使用手机上的文件应用程序创建一个文件夹以查看一些反馈。如果你想在其中放入文件,请使用Swift的fileExporter。
英文:
I found the answer to my own question:
I had to "import UniformTypeIdentifiers"
Xcode doesn't complain about not having it, it just doesn't show any files or folders. Only indicator was a different color for the element in the allowedContentTypes: [] collection.
Edit: For those still not seeing much: the Xcode iPhone Simulator doesn't have any example/inital files or folders in there. I'd recommend to create a folder with the files app on the phone to see some feedback. If you want files in there use Swift's fileExporter.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论