我正在使用TPPDF库制作PDF.这使得PDF很好,并返回URL,如下所示:
pdfURL=file:///Users/taimoorarif/Library/Developer/CoreSimulator/Devices/8A2723A7-DD69-4551-A297-D30033734181/data/Containers/Data/Application/EE60FB55-13AE-4658-A829-8A85B2B6ED95/tmp/SwiftUI.pdf
如果我在Google Chrome中打开这个URL,这个shows是我的PDF.但是当我try 使用
UIApplication.共享.打开(pdfURL)
它什么也没做.
我还制作了一个UIViewRepresentable PDFKitView:
import SwiftUI
import PDFKit
struct PDFKitView: View {
var url: URL
var body: some View {
PDFKitRepresentedView(url)
}
}
struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL
init(_ url: URL) {
self.url = url
}
func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
let pdfView = PDFView()
pdfView.document = PDFDocument(url: self.url)
pdfView.autoScales = true
return pdfView
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
// Update the view.
}
}
并将其用作:
PDFKitView(url: URL(string: pdfURL.absoluteString))
它也不起作用.
I know此url是保存此文件的路径.所以,在搜索了这个之后,我试着:
让fileURL=Bundle.主要的url(用于资源:pdfURL,扩展名为:"pdf")!
应用程序在此崩溃并出现错误:
在展开可选值时意外发现nil
这里的question个是我想在我的应用程序中打开这个PDF,无论它是在Safari还是Google Drive打开,但不知道怎么做.那么我如何打开我的PDF?