美文网首页日常小知识点
iOS图片保存到相册的方法(Objective - C)

iOS图片保存到相册的方法(Objective - C)

作者: 张俊凯 | 来源:发表于2018-06-14 11:50 被阅读29次

第一种方法:

UIImageWriteToSavedPhotosAlbum(ImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

此种方法失败几率很高

第二种方法

NSError *error = nil;
  [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
        [PHAssetChangeRequest creationRequestForAssetFromImage:cell.adImageView.image];
    } error:&error];

此种方法是同步操作,需要等待存储过程完成

补充方法

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        
    }]

此方法是异步操作,如果完成后需要别的操作可能会出现问题,需要额外注意

the end.

相关文章

网友评论

    本文标题:iOS图片保存到相册的方法(Objective - C)

    本文链接:https://www.haomeiwen.com/subject/spqreftx.html