将网络请求下的图片保存在本地相册,代码如下:
#pragma mark 保存图片到本地相册
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@""] style:UIBarButtonItemStylePlain target:self action:@selector(savePictureAction:)];
- (void)savePictureAction:(UIButton *)button
{
UIImageView *imageView = [[UIImageView alloc] init];
[imageView sd_setImageWithURL:[NSURL URLWithString:self.Url] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[self saveImageToPhotos:image];
}];
}
- (void)saveImageToPhotos:(UIImage*)image
{
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error != NULL)
{
//收藏失败
else
{
//收藏成功
}
}