iphoneobjective-ciosalassetslibrary

Save UIImage to Photo Album with writeImageToSavedPhotosAlbum


I'm trying to save a UIImage to Photo Album. I've tried severl methods the last one is:

-(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 is a UIImageView which contain the image I want to save. On log I got "PHOTO SAVED - assetURL: (null)" and the photo doesn't save to library.

What am I doing wrong?


Solution

  • I'm using GPUImage, Apparently there is some kind of problem with the library itself.

    The code above is absolutely working. If you want to read more about this issue:

    GPUImagePicture with imageFromCurrentlyProcessedOutput doesn't get UIImage