[英]SDWebImage Download Image Completion Block not being called
所以SDWebImage下載圖像並存儲到密鑰緩存中,這正是我想要在應用程序中執行的操作。 我想將圖像存儲在密鑰中,然后再獲取圖像。 這是我的代碼塊:
SDWebImageManager.shared().imageDownloader?.downloadImage(with: URL.init(string: url), options: SDWebImageDownloaderOptions.highPriority, progress: { (receivedSize:Int,expectedSize:Int,url : URL?) in
print("progressing here in this block ")
}, completed: ({(image : UIImage, data : Data,error : Error, finished : Bool) in
print("reached in the completion block ")
if finished {
SDImageCache.shared().store(image, forKey: "d", toDisk: true, completion: nil)
} else {
print(error.localizedDescription)
showAlert(viewController: self, title: "", message: error.localizedDescription)
}
} as? SDWebImageDownloaderCompletedBlock))
但是,從未調用完成塊。
使用這段代碼:
SDWebImageManager.shared().loadImage(with: NSURL.init(string: individualCellData["cover_image"] as! String ) as URL?, options: .continueInBackground, progress: { (recieved, expected, nil) in
print(recieved,expected)
}, completed: { (downloadedImage, data, error, SDImageCacheType, true, imageUrlString) in
DispatchQueue.main.async {
if downloadedImage != nil{
self.yourImageView.image = downloadedImage
}
}
})
而且您不必像SDWebImage已經做的那樣再次緩存圖像。 要從緩存中檢索圖像,只需在此代碼中使用相同的url,如果存在,它將從緩存中獲取圖像。
更新的代碼:
如果要使用自己的密鑰,請使用imageDownloader而不是loadImage:
SDWebImageManager.shared().imageDownloader?.downloadImage(with: NSURL.init(string: individualCellData["cover_image"] as! String ) as URL?, options: .continueInBackground, progress: { (recieved, expected, nil) in
print(recieved,expected)
}, completed: { (image, data, error, true) in
print("Completed")
})
在print("Completed")
如果沒有錯誤,請使用您的緩存代碼通過您的自定義鍵來緩存圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.