UIDocumentPickerViewController in SwiftUI on mac (macCatalyst)

ぃ、小莉子 提交于 2019-12-11 16:24:59

问题


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 UIDocumentPickerViewControllerdoesnt show and we get this blank modal:

来源:https://stackoverflow.com/questions/59078623/uidocumentpickerviewcontroller-in-swiftui-on-mac-maccatalyst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!