-(void)setItem:(CustomItem*)item{
_item= item;
//占位图片
UIImage*placeholder = [UIImageimageNamed:@"placeholderImage"];
//从内存\沙盒缓存中获得原图
UIImage*originalImage = [[SDImageCachesharedImageCache]imageFromDiskCacheForKey:item.originalImage];
if(originalImage) {
//如果内存\沙盒缓存有原图,那么就直接显示原图(不管现在是什么网络状态)
[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];
}else{
//内存\沙盒缓存没有原图
AFNetworkReachabilityManager*mgr = [AFNetworkReachabilityManagersharedManager];
NSLog(@"%s,%d",__FUNCTION__,mgr.isReachableViaWiFi);
if(mgr.isReachableViaWiFi) {
//在使用Wifi,下载原图
[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];
}elseif(mgr.isReachableViaWWAN) {
//在使用手机自带网络
#warning从沙盒中读取用户的配置项:在3G\4G环境是否仍然下载原图
BOOLalwaysDownloadOriginalImage = [[NSUserDefaultsstandardUserDefaults]boolForKey:@"alwaysDownloadOriginalImage"];
if(alwaysDownloadOriginalImage) {
//下载原图
[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];
}else{
//下载小图
[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.thumbnailImage]placeholderImage:placeholder];
}
}else{
//没有网络
UIImage*thumbnailImage = [[SDImageCachesharedImageCache]imageFromDiskCacheForKey:item.thumbnailImage];
if(thumbnailImage) {
//内存\沙盒缓存中有小图
[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.thumbnailImage]placeholderImage:placeholder];
}else{
[self.mainImageViewsd_setImageWithURL:nilplaceholderImage:placeholder];
}
}
}
}