您的当前位置:首页SDWebImage 相同 URL, 不同 Image 处理

SDWebImage 相同 URL, 不同 Image 处理

2024-12-12 来源:哗拓教育

原因

因为 SDWebImage 的缓存机制, 相同的 URL 它就认为可以去到沙盒里面的缓存路片

解决方法

NSString *testImageUrl = 
[_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;
}
显示全文