我在应用程序中使用SDWebImage
从网络加载和缓存图像。它的工作原理就像是一种魅力,但是唯一的问题是,每当我退出应用程序时,即使是暂时退出,图像缓存也会被清除,所有图像都必须再次下载。 Internet连接速度慢时,这尤其是个问题。我希望在返回应用程序时保留图像。有谁知道如何实现这一目标?
最佳答案
转到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];
随意注释掉或更改任何内容。我可以选择关闭这些代码行。
关于ios - SDWebImage-避免在进入背景时清除图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20353551/