Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中将PDF转换为数据失败_Ios_Wkwebview_Ios Pdfkit - Fatal编程技术网

在iOS中将PDF转换为数据失败

在iOS中将PDF转换为数据失败,ios,wkwebview,ios-pdfkit,Ios,Wkwebview,Ios Pdfkit,我正在尝试在iOS应用程序中打开一个受密码保护的PDF。 为此,我使用PDFKit打开文档,解锁文档,然后尝试将文档转换为数据。这个数据然后可以在webview中加载,这就是我想要做的。 但是,在将文档转换为数据时,我发现加载失败错误,因此在webView中加载空白pdf func loadData() -> Data { let pdfView = PDFView(frame: self.view.bounds) let fileURL = Bundle.main.url(f

我正在尝试在iOS应用程序中打开一个受密码保护的PDF。 为此,我使用
PDFKit
打开文档,解锁文档,然后尝试将文档转换为
数据。这个
数据
然后可以在webview中加载,这就是我想要做的。 但是,在将文档转换为
数据
时,我发现
加载失败
错误,因此在
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
 }