【发布时间】:2021-10-18 09:23:11
【问题描述】:
我在 SwiftUI 中使用 .fileImporter 修饰符在我的应用程序中导入 pdf 文件。我有几个问题。首先,数据加载速度很慢,并且经常无法加载并给出消息内部错误无法与帮助应用程序通信。
但主要问题是,如果模式视图通过向下滑动关闭,则无法再次呈现。大概是因为绑定 $showFileImporter 没有重置。如果按下取消按钮以将其关闭,则它可以正常工作。我不知道是否有强制它全屏来解决这个问题。
这是我的代码:
.fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.pdf]) { result in
switch result {
case .success(let url):
url.startAccessingSecurityScopedResource()
if let pDFDocument = PDFDocument(url: url) {
if let data = pDFDocument.dataRepresentation() {
// handle data
}
}
case .failure(let error):
print(error)
}
}
【问题讨论】:
标签: ios xcode swiftui swiftui-fileimporter