我正在尝试将 UIImage 保存到相册。我尝试了几种方法,最后一种是:
-(IBAction)captureLocalImage:(id)sender{
[photoCaptureButton setEnabled:NO];
// Save to assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum: imageView.image.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error2)
{
// report_memory(@"After writing to library");
if (error2) {
NSLog(@"ERROR: the image failed to be written");
}
else {
NSLog(@"PHOTO SAVED - assetURL: %@", assetURL);
}
runOnMainQueueWithoutDeadlocking(^{
// report_memory(@"Operation completed");
[photoCaptureButton setEnabled:YES];
});
}];
}
imageView 是一个 UIImageView ,其中包含我要保存的图像。在日志上,我得到“照片已保存-assetURL:(null)”并且照片没有保存到库中。
我究竟做错了什么?