NSString * filepath=xxxxx;
if ([[NSFileManager defaultManager]fileExistsAtPath:filepath]) {
//异步加载图片
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage * img=[UIImage imageWithContentsOfFile:filepath];
dispatch_sync(dispatch_get_main_queue(), ^{
self.bgImageView.image=img;
});
});
}else{
[self.bgImageView sd_setImageWithURL:[NSURL URLWithString:imageUrlstr] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
// 判断本地图片是否存在 不存在写入本地
NSString *typePath=[[ShareMethod appRootPath] stringByAppendingPathComponent:FangAnBrowseFolder];
[FileFunction createFolderAtPath:typePath folderName:solationID];
//异步保存图片
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
BOOL issuc = [UIImagePNGRepresentation(image) writeToFile:filepath atomically:YES];
NSLog(@"issuc==%d",issuc);
dispatch_sync(dispatch_get_main_queue(), ^{
});
});
}];
}