问题
So I've been meddling with "moving" a small SwiftUI iPad app to the Mac, and I've hit a bit of a speed bump with UIDocumentPickerViewController
.
I have wrapped the UIDocumentPickerViewController
in a UIViewControllerRepresentable
like so :
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) {
}
}
And displaying it like this:
struct ContentView: View {
@State var shows = false
var body: some View {
Button(action: { self.shows.toggle() }) {
Text("Select File")
}
.sheet(isPresented: self.$shows) {
DocumentPickerView()
}
}
}
On the iPad all is working well,
But when on on the Mac, the UIDocumentPickerViewController
doesnt show and we get this blank modal:
来源:https://stackoverflow.com/questions/59078623/uidocumentpickerviewcontroller-in-swiftui-on-mac-maccatalyst