日常收录

iOS保存图片到相册

2020-08-18  本文已影响0人  MonKey_Money

UIKit框架下的保存图片

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

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error) {
        NSLog(@"保存失败");
    } else {
        NSLog(@"保存成功");
    }
    
}

Photos框架下保存图片

//第一个方法
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [PHAssetChangeRequest creationRequestForAssetFromImage:image];
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            NSLog(@"成功");
        } else {
            NSLog(@"失败");
        }

    }];
//第二个方法
   BOOL isSuccess =  [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
        [PHAssetChangeRequest creationRequestForAssetFromImage:image];

    } error:&error];
    if (isSuccess) {
        NSLog(@"成功");
    } else {
        NSLog(@"失败");

    }
上一篇下一篇

猜你喜欢

热点阅读