NSOperation下载图片-04
cell 的图片下载
1,面试题
1》如何防止一个url对应的图片重复下载?
*cell下载图片-有沙盒缓存
2》SDWebImage的默认缓存时长是多少?
*一个星期
3》SDWebImage底层是怎样实现的?
*cell下载图片-有沙盒缓存
2,SDWebImage
1》常用方法
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
2》内存处理:当app接收到内存警告时
// 当app接收到内存警告
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
SDWebImageManager *mgr = [SDWebImageManager sharedManager];
// 1,取消正在下载对操作
[mgr cancelAll];
// 2,清除内存缓存
[mgr.imageCache clearMemory];
// mgr.imageCache.maxCacheAge = 1 * 24 * 60 * 60 * 7; // one week
// mgr.imageCache.maxCacheSize // bytes
}
3》SDWebImageOptions参数
*SDWebImageRetryFailed:下载失败后,会自动尝试下载
*SDWebImageLowPriority:当正在进行一些UI交互时,自动暂停内部一些下载操作
*SDWebImageRetryFailed | SDWebImageLowPriority:拥有上面2个功能