我SDWebImage
在我的应用程序中使用来加载和缓存来自网络的图像。它就像一个魅力,但唯一的问题是,每当我退出我的应用程序时,即使是暂时的,图像缓存都会被清除,并且必须重新下载所有图像。当 Internet 连接速度较慢时,这尤其是一个问题。我希望在返回应用程序时保留图像。有谁知道如何实现这一目标?
1965 次
2 回答
2
转到 SDImageCache.m 并查找方法 - (id)initWithNamespace:(NSString *)ns 在那里你会发现这样的代码:
// Subscribe to app events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearMemory)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(cleanDisk)
name:UIApplicationWillTerminateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backgroundCleanDisk)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
如果您愿意,请随时评论或更改任何内容。我会选择关闭这些代码行。
于 2013-12-09T13:50:39.900 回答
1
确保您没有设置maxCacheSize
of [SDImageCache sharedImageCache]
,如果在应用程序进入后台时设置了它,它将清除缓存文件以适应maxCacheSize
.
在cleanDisk
方法中,您可以看到在删除文件之前有一个检查
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize)
{
// ...
}
所以如果maxCacheSize
没有设置,它什么也不做。
于 2014-01-07T05:42:15.820 回答