首先,我沒有找到關於它的點兒上這個網站後,再次下載。防止影像回去或終止應用程序的所有我想說的
我要救NSURL
爲NSUserDefaults
,以防止對每一個應用程序打開或視圖中打開加載圖像。我試圖這樣做,但由於某種原因,我不能。至少我認爲那應該做什麼:
let productImageref = productsValue[indexPath.row]["Products"] as? String
cell.snusProductImageView.image = nil
if let url = self.productsValue[indexPath.row]["imageUrl"] as? NSURL {
cell.snusProductImageView.kf_showIndicatorWhenLoading = true
var storedUrl = defaults.objectForKey("imageUrl") as? NSURL
cell.snusProductImageView.kf_setImageWithURL(storedUrl)
}
else {
FIRStorage.storage().reference().child("\(productImageref!).png").downloadURLWithCompletion({(url, error)in
if error != nil{
print(error)
return
}else{
self.productsValue[indexPath.row]["imageUrl"] = url
self.defaults.setURL(url, forKey: "imageUrl")
self.productstable.reloadData()
dispatch_async(dispatch_get_main_queue(), {
})
}
})
}
如果我錯了,那麼請糾正我。應該保存url-s到userdefaults
做詭計嗎?
正是我做錯了什麼?也許最好將它保存到CoreData
,但我認爲這將是矯枉過正。
爲什麼KingFisher或SDWebImages庫沒有緩存它?
我強烈建議看一看http://stackoverflow.com/questions/38943645/uploading-downloading-multiple-images-the-right-way,並將其與SDWebImage或PINRemoteImage等工具一起使用。還有比CoreData和'NSUserDefaults'更好的解決方案爲這個應用程序:) –
哦..最後的東西是不downvote。所以根據你所說的我明白,下載網址永遠不會改變?所以我不需要將它們存儲到數組和userdefaults中? –
不是,兩種URL類型('gs://'和'https://')都是穩定的。你會想要使用公共的'https://'用於第三方映像加載庫或緩存。實時數據庫也具有離線持久性,因此您不必在冷啓動時獲取URL。) –