美文网首页很常
iOS开发中实现同时将多张照片写入到本地相册中

iOS开发中实现同时将多张照片写入到本地相册中

作者: 梁森的简书 | 来源:发表于2021-02-20 10:46 被阅读0次

    代码:

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        NSArray * images = @[[UIImage imageNamed:@"11 pro Max"], [UIImage imageNamed:@"11 pro Max"], [UIImage imageNamed:@"11 pro Max"]];
        for (int i = 0; i < images.count; i ++) {
            UIImage * image = images[i];
            NSLog(@"%@", [NSThread currentThread]);
            [self loadImageFinished:image];
        }
    }
    
    - (void)loadImageFinished:(UIImage *)image{
        [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            NSLog(@"%@", [NSThread currentThread]);
            //写入图片到相册
            [PHAssetChangeRequest creationRequestForAssetFromImage:image];
        } completionHandler:^(BOOL success, NSError * _Nullable error) {
            NSLog(@"success = %d, error = %@", success, error);
            if(success){
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"保存成功");
                });
            } else {
                NSLog(@"保存不成功");
            }
        }];
    }
    

    [PHPhotoLibrary sharedPhotoLibrary] performChanges...方法可以在子线程中保存图片到本地。

    相关文章

      网友评论

        本文标题:iOS开发中实现同时将多张照片写入到本地相册中

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