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:
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.