我正在使用 SDWebImage
异步显示图像,缓存它们,然后在离线模式下获取它们。
我在使用离线模式时遇到了 SDWebImageDownloader
和 UIImageView+WebCache
缓存的问题,并且该问题仅在处理百分比转义 URL 时出现,这些 URL 具有一些特殊的像“{”这样的字符。
在在线模式下一切正常,但在离线模式下,无法加载包含百分比转义的 URL 的图像
[myImageView setImageWithURL:[urlImage percentEscapedURL]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//image here is loaded in offline mode only if its URL does not need percent escapes
}];
SDWebImageDownloader
也有同样的问题。
我尝试调试 SDImageView
行为,它似乎正在使用 iOS SDK NSCachedURLResponse
行为。
我正在测试 https://github.com/rs/SDWebImage/使用 iOS 7.0
有人遇到过同样的问题吗?任何解决方法?
最佳答案
SDWebImage 在 SDWebImageManager.h
中声明了一些属性:
@property (strong) NSString *(^cacheKeyFilter)(NSURL *url);
相应文件中有对该属性的描述:
/**
* The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
* be used to remove dynamic part of an image URL.
*
* The following example sets a filter in the application delegate that will remove any query-string from the
* URL before to use it as a cache key:
*
* @code
[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
return [url absoluteString];
}];
* @endcode
*/
我觉得你可以试着对相应的代码做一些改动。
关于ios - 脱机时 SDWebImageView 缓存问题和转义 URL 百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23078917/