我試圖加載存儲在公共數據庫中的PDF文件作爲CKAsset,代碼在去年發佈的現有應用程序中運行良好。不過,我現在得到以下錯誤將CKAsset加載到UIWebView中
無法將類型「的NSData」的價值強制
這裏鍵入「數據」是代碼 -
if docType == "PDF" || docType == "pdf" {
if let asset1 = record.object(forKey: "documentFile") as? CKAsset {
let doc1Data : NSData? = NSData(contentsOf:asset1.fileURL)
let path = (NSTemporaryDirectory() as NSString).appendingPathComponent(filename)
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(filename)
do {
try doc1Data!.write(to: URL(fileURLWithPath: path), options: .atomic)
} catch {
print(error)
}
self.docWebView.load(doc1Data! as Data, mimeType: "application/pdf", textEncodingName: "UTF-8", baseURL: NSURL() as URL)
self.filenameURL = [(fileURL)]
}
我敢肯定,必須有一個簡單的解釋,但我不能看到問題
在此先感謝。
唉我仍然得到錯誤 - 無法將類型'NSData'的值轉換爲在'co'中鍵入'數據' ercion涉及到'self.docWebView.loadData(doc1Data as Data ?, MIMEType:「application/pdf」,textEncodingName:「UTF-8」,baseURL:NSURL()爲URL)'代碼行 – Bowcaps