如何使用Swift将带有pdf的webview页面加载到ibooks中
这是我能找到的最接近的代码,但没有使用包含pdf文件的webview页面的语法 var docController:UIDocumentInteractionController 如果let path=NSBundle.mainBundle().pathForResource(“book”,类型为“pdf”){ 如果让targetURL=NSURL.fileURLWithPath(路径){如何使用Swift将带有pdf的webview页面加载到ibooks中,swift,pdf,webview,ibooks,Swift,Pdf,Webview,Ibooks,这是我能找到的最接近的代码,但没有使用包含pdf文件的webview页面的语法 var docController:UIDocumentInteractionController 如果let path=NSBundle.mainBundle().pathForResource(“book”,类型为“pdf”){ 如果让targetURL=NSURL.fileURLWithPath(路径){ }在ibooks中打开之前,您发现需要将pdf文件写入设备。以下是有效的代码: func download
}在ibooks中打开之前,您发现需要将pdf文件写入设备。以下是有效的代码:
func downloadPDF() {
// Running operations that takes a long time in a background thread is recommended
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
// Get the PDF data from the URL
let url = self.webview.request?.URL
let pdfURL = url?.absoluteString
let pdfData = NSData(contentsOfURL: NSURL(string: pdfURL!)!)!
// Store the data locally as a PDF file in the Documents directory
let documentsDirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String
localPdfPath = documentsDirPath.stringByAppendingPathComponent(pdfURL!.lastPathComponent)
pdfData.writeToFile(localPdfPath, atomically: true)
// UI related stuff should be called in the main thread.
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.openIniBooks()
IJProgressView.shared.hideProgressView()
})
})
}
在ibooks中打开之前,您发现需要将pdf文件写入设备。以下是有效的代码:
func downloadPDF() {
// Running operations that takes a long time in a background thread is recommended
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
// Get the PDF data from the URL
let url = self.webview.request?.URL
let pdfURL = url?.absoluteString
let pdfData = NSData(contentsOfURL: NSURL(string: pdfURL!)!)!
// Store the data locally as a PDF file in the Documents directory
let documentsDirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String
localPdfPath = documentsDirPath.stringByAppendingPathComponent(pdfURL!.lastPathComponent)
pdfData.writeToFile(localPdfPath, atomically: true)
// UI related stuff should be called in the main thread.
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.openIniBooks()
IJProgressView.shared.hideProgressView()
})
})
}
我高估了你的票数,因为这是一个措辞得体的问题,我也在寻找这个问题的答案,但一直找不到。如果我遇到任何问题,我会把它放在这里。我高估了你的票数,因为这是一个措辞得体的问题,我也在寻找这个问题的答案,但一直找不到。如果我遇到任何问题,我会把它放在这里重新。