[英]How can I grab a pdf file from the files app in SwiftUI and import it into my app on an iPhone with iOS
我希望能够将 pdf 个文件从文件应用程序导入我的应用程序,但不确定如何实现。
当您向 email 添加附件时,是否有 FilePicker 或类似的东西可以用于与苹果邮件应用程序类似的行为? 使用邮件应用程序,当您按“添加文档”时,它会打开一个文档浏览器,您可以 select 一个文件。 我相信这是来自 iCloud Drive。
您可以在 SwiftUI 中使用.fileImporter
:
struct ContentView : View {
@State private var presentImporter = false
var body: some View {
Button("Open") {
presentImporter = true
}.fileImporter(isPresented: $presentImporter, allowedContentTypes: [.pdf]) { result in
switch result {
case .success(let url):
print(url)
//use `url.startAccessingSecurityScopedResource()` if you are going to read the data
case .failure(let error):
print(error)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.