UIImageView *gtp = [[UIImageView alloc] init];
[gtp sd_setImageWithURL:[NSURL URLWithString:@"https://wx1.sinaimg.cn/mw690/00632esply1fnloc9x8fgj31kw16ou0y.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"]];
[gtp sd_setImageWithPreviousCachedImageWithURL:[NSURL URLWithString:@"https://wx1.sinaimg.cn/mw690/00632esply1fnloc9x8fgj31kw16ou0y.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"] options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
NSLog(@"已接收%f,总大小%ld",(CGFloat)receivedSize,(long)expectedSize);
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//url加载完 在保存图片
UIImageWriteToSavedPhotosAlbum(gtp.image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
}];
//保存完成后调用的方法
- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError *)error contextInfo: (void *)contextInfo {
if (error) {
NSLog(@"保存图片出错%@", error.localizedDescription);
}
else {
NSLog(@"保存图片成功");
}
}
网友评论