ios - 脱机时 SDWebImageView 缓存问题和转义 URL 百分比

标签 ios objective-c sdwebimage nsurlcache

我正在使用 SDWebImage 异步显示图像,缓存它们,然后在离线模式下获取它们。

我在使用离线模式时遇到了 SDWebImageDownloaderUIImageView+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/

相关文章:

ios - 多个UITableViewCells在点击时会做不同的事情

objective-c - NSUserDefults 返回 null

ios - 修复 Xcode 中的 "Lexical or Preprocessor Issue - Extension used"警告?

ios - 当navigationBar.isTranslucent为true时,navigationbar的backgroundImage也变成半透明

iOS/objective-C : Swipe to Left causing crash in tableview created with code

Objective-C 将基类对象转换为特定类

ios - Apple M1 芯片上的 Firebase 分析和其他模块

objective-c - 添加SDWebImage框架时出现Xcode Clang错误

ios - SdWebImage 问题中的事件指示器

适用于 Android、iOS 和 BB 的 ASP.NET Web 服务