wangyang1213

iOS 拍照保存到相册

之前看了一些开源的代码,里面有一个功能,就是将图片下载到相册,仔细看了其中的代码,只有很简单的一句话,并且保存过后,还可以判断是否保存成功。

如下代码所示,

点击按钮,将self.imageView上面的image内容保存到本地相册,并指定判断保存成功与否的方法imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:

- (IBAction)saveImageToAlbum:(id)sender {
    UIImageWriteToSavedPhotosAlbum(self.imageView.imageself@selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}

实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:方法

- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    NSString *message = @"呵呵";
    if (!error) {
        message = @"成功保存到相册";
    }else
    {
        message = [error description];
    }
    NSLog(@"message is %@",message);
}

这些代码很简单,如果没有错误的话就提示“成功保存到相册”,如果保存失败的话,那么就输出错误信息[error description]。

发表于 2016-04-14 11:11  小荷才露尖尖角1213  阅读(345)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2022-02-21
  • 2022-01-31
  • 2021-05-24
  • 2021-09-11
  • 2022-12-23
  • 2021-07-06
相关资源
相似解决方案