我将pdf存储在文档目录中,我想打开此pdf文件
let documentsURL = try! FileManager().url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
let path = documentsURL.appendingPathComponent("myFile.pdf")
答案 0 :(得分:0)
您可以使用QLPreviewController将QuickLook导入控制器
打开pdf文件import QuickLook
func openQlPreview() {
let previoew = QLPreviewController.init()
previoew.dataSource = self
previoew.delegate = self
self.present(previoew, animated: true, completion: nil)
}
extension UIViewController : QLPreviewControllerDelegate , QLPreviewControllerDataSource{
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
// pass your document url here
return path as QLPreviewItem
}
func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool {
return true
}
}