因此,我一直在干预将一个小型SwiftUI iPad应用“移动”到Mac,并且使用UIDocumentPickerViewController
遇到了一些麻烦。
我将UIDocumentPickerViewController
包裹在UIViewControllerRepresentable
中,如下所示:
struct DocumentPickerView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let documentPicker = UIDocumentPickerViewController(documentTypes: [(kUTTypeImage as String)],in: .import)
return documentPicker
}
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController,context: Context) {
}
}
并显示如下:
struct ContentView: View {
@State var shows = false
var body: some View {
Button(action: { self.shows.toggle() }) {
Text("Select File")
}
.sheet(isPresented: self.$shows) {
DocumentPickerView()
}
}
}
但是在Mac上,UIDocumentPickerViewController
并没有显示,我们得到了这个空白模态: