SDWebImage 相同 URL, 不同 Image 處理

原因

因為 SDWebImage 的緩存機制, 相同的 URL 它就認為可以去到沙盒里面的緩存路片

解決方法

NSString *testImageUrl = "www.你的image.com";
[_IMG sd_setImageWithURL:[NSURL URLWithString:testImageUrl] placeholderImage:[UIImage imageNamed:@"1.png"] options:SDWebImageRefreshCached];

SDWebImageManager.m文件中,大概176行左右吧,把之前的代碼:(如下)

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

更換成如下代碼:

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
    // remove SDWebImageDownloaderUseNSURLCache flag
    downloaderOptions &= ~SDWebImageDownloaderUseNSURLCache;
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容