Ios – Save UIImage to Photo Album with writeImageToSavedPhotosAlbum

alassetslibraryiosiphoneobjective c

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?

Best Answer

just use this bellow line for save the image in your photo library

UIImageWriteToSavedPhotosAlbum(imageView.image,nil,nil,nil);

:)

Related Topic