我已经使用Alamofire实现了下载文件功能。文件下载成功,但是当我尝试在本地读取文件时,它总是给我 在线错误:
响应本地文件位置: 代码:Fatal error: Unexpectedly found nil while unwrapping an Optional value
。如果我将粘贴本地文件链接复制到浏览器,则会打开文件或在Finder
中打开文件。 pdfView.document = PDFDocument(url: fileURL!)
/Users/abc/Library/Developer/CoreSimulator/Devices/4B6C2727-46AB-4797-8CBB-D5A897867013/data/Containers/Data/Application/C782E91D-9E63-4D1D-BBB3-2CD0414E6EA6/Documents/3602319458509320922.pdf
let fileType = (URL != nil) ? ".pdf" : ".png"
DataProvider.main.downloadFile(url: String(describing: self.URL!), filetype: fileType, callback: { success, response in
if !success || response == nil {
return false
}
if((response as! String).hasSuffix("pdf")){
print(response)
let fileURL = Bundle.main.url(forResource: response as? String, withExtension: "pdf")
pdfView.document = PDFDocument(url: fileURL!)
}else if (FileManager.default.fileExists(atPath: (response as! String).removingPercentEncoding!) ){
let fileURL = Bundle.main.url(forResource: response as? String, withExtension: "pdf")
pdfView.document = PDFDocument(url: fileURL!)
}
return true
})
0 个答案:
没有答案