gpt4 book ai didi

ios - Mac 上 SwiftUI 中的 UIDocumentPickerViewController (macCatalyst)

转载 作者:行者123 更新时间:2023-12-04 04:27:53 25 4
gpt4 key购买 nike

所以我一直在忙着将一个小的 SwiftUI iPad 应用程序“移动”到 Mac 上,我遇到了一点减速带 UIDocumentPickerViewController .
我已经包裹了UIDocumentPickerViewControllerUIViewControllerRepresentable像这样:

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()
}
}
}

在 iPad 上一切正常,
iPad

但是在 Mac 上时, UIDocumentPickerViewController不显示,我们得到这个空白模式:

Mac

最佳答案

我替换了不推荐使用的方法,并为提供的主题启动代码启用了询问权利,它可以工作。
使用 Xcode 13.3/macOS 12.2 测试

import UniformTypeIdentifiers
struct DocumentPickerView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.image], asCopy: true)
return documentPicker
}

func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {

}
}
config
和演示打开标准 macOS 选择器
enter image description here

关于ios - Mac 上 SwiftUI 中的 UIDocumentPickerViewController (macCatalyst),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59078623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com