代码:
- (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...方法可以在子线程中保存图片到本地。
网友评论