美文网首页日常收录
iOS保存图片到相册

iOS保存图片到相册

作者: MonKey_Money | 来源:发表于2020-08-18 14:46 被阅读0次

    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(@"失败");
    
        }
    

    相关文章

      网友评论

        本文标题:iOS保存图片到相册

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