问题描述
我正在尝试在受密码保护的iOS应用中打开PDF。
为此,我使用PDFKit
打开文档,解锁文档,然后尝试将文档转换为Data
。然后可以在Webview中加载此Data
,这是我要执行的操作。
但是,在将文档转换为Data
时,出现Failed to load
错误,因此在webView
中加载了空白pdf。
func loadData() -> Data
{
let pdfView = PDFView(frame: self.view.bounds)
let fileURL = Bundle.main.url(forResource: "myDocument",withExtension: "pdf")
var pdfData:Data?
if let document = PDFDocument(url: fileURL!) {
if(document.isLocked){
document.unlock(withPassword: "0123")
print("Unlocked successfully!") //This is printed as expected
}
pdfData = document.dataRepresentation() // At this point I am getting -> [Unknown process name] Failed to load /System/Library/PrivateFrameworks/CorePDF.framework/Versions/A/CorePDF
}
func createWebView(withFrame frame: CGRect) -> WKWebView? {
let webView = WKWebView(frame: frame)
webView.autoresizingMask = [.flexibleWidth,.flexibleHeight]
let pdfdata = loadData() //Called here.
webView.load(pdfdata,mimeType: "application/pdf",characterEncodingName:"utf-8",baseURL: URL(fileURLWithPath: ""))
return webView
}
return nil
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)