我在我的应用程序中添加了 QuickLook 以显示文档目录中的文档、pdf 等,它在模拟器中工作正常但在 iPad 中它只显示文件名作为标题和灰色屏幕而不是 pdf 页面,不知道出了什么问题这里有代码
docUrlLocal = jobDocument.docFileLocal
docUrlLocal = docUrlLocal.replacingOccurrences(of: "file://", with: "")
/* Simulator path /Users/varunnaharia/Library/Developer/CoreSimulator/Devices/86CE9E4C-7D50-4831-934C-442A7558024C/data/Containers/Data/Application/86E66141-4F69-4347-81B5-415F805884C1/Documents/33fe5731-129a-4b8e-aa67-c3e840a69677.pdf
iPad Path /var/mobile/Containers/Data/Application/743CEA41-89F4-4EEF-84E5-FCECA1FCB038/Documents/33fe5731-129a-4b8e-aa67-c3e840a69677.pdf
*/
let ql = QLPreviewController()
ql.dataSource = self
parentVC.present(ql, animated: true, completion: nil)
以及下载和保存文档的代码
let fileName = (self.docURL as NSString).lastPathComponent
let fullFilePath = URL(fileURLWithPath:
FileManager.documentsDir()).appendingPathComponent("\(fileName)")
let destination =
DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(
self.docURL,
method: .get,
parameters: nil,
encoding: JSONEncoding.default,
headers: nil,
to: destination).downloadProgress(closure: { (progress) in
//progress closure
}).response(completionHandler: { (DefaultDownloadResponse) in
//here you able to access the DefaultDownloadResponse
//result closure
self.jobDocument.docFileLocal = fullFilePath.absoluteString
self.parentVC.tblView.reloadData()
self.btnOpen.isHidden = true
})
最佳答案
Idk,如果那真的是你的问题,我是这样解决的:
let filename = name.fileName().replacingOccurrences(of: ".", with: " ")
let fileExtension = name.fileExtension()
let fixedFileTypeName = filename + fileExtension
所以问题出在文件名 (url) 中的点
关于ios - QuickLook 不显示仅以文件名作为标题的 pdf 灰色屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46116413/