PDFDocument无法从URL加载文件

问题描述 投票:0回答:1

我正在使用PDFKit通过PDFView功能在pdfView.document = document中显示PDF文件。

这里是问题,我也使用UIDocumentPicker API,每当我从didPickDocumentAt url委托方法检索文档URL时,URL字符串的格式如下:

file:///private/var/mobile/Containers/Data/Application/09281711-BFB5-4B74-94A1-473F9B460EBD/tmp/com.ivancantarino.Cozynote-Inbox/Documento%20PDF.pdf

[如果以后我尝试使用PDFKit预览该文档,则不会实例化该文档本身。

这里是示例代码:

let pdfView = PDFView()
pdfView.autoScales = true
view.addSubview(pdfView)
pdfView.frame = view.frame

// ... getting the document url, which comes in the following form: 
// file:///private/var/mobile/Containers/Data/Application/09281711-BFB5-4B74-94A1-  473F9B460EBD/tmp/com.ivancantarino.Cozynote-Inbox/Documento%20PDF.pdf
// I'm saving the URL as a string, due to the databse entry
let url: String = ...
let document = PDFDocument(url: url)
pdfView.document = document

document变量始终为nil,它无法将网址识别为合法路径。

我在这里做错什么了吗,或者有一种方法可以以任何不同的方式来做到这一点?

谢谢。

ios swift pdfkit
1个回答
0
投票

Delegate:-UIDocumentInteractionControllerDelegate

© www.soinside.com 2019 - 2024. All rights reserved.