0

My problem is really annoying. I'm creating app which takes photos and need to save them to custom gallery. I've found a couple of tutorials how to do this with AlAssetsLibrary but there is one, big problem... There is no saveImage:toAlbum:withCompletionBlock: method. I've used addAssetsGroupAlbumWithName:resultBlock:failureBlock: to create custom photo album but there is no way I can save images to this gallery! I'm using iOS 6 iPhone 4.

Any ideas!?

cojoj
  • 6,405
  • 4
  • 30
  • 52
  • 1
    Have you checked [this](http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/) ? – TheTiger Jul 18 '13 at 09:40
  • Yeah, I saw this earlier but look at my comment under @Vignesh answer :) – cojoj Jul 18 '13 at 10:07

3 Answers3

1

The method you mentioned in the question saveImage:toAlbum:withCompletionBlock is not part of ALAssetsLibrary. This method is written in ALAssetLibary's category. You got to import the category in your class to use the method.

To learn more about objective C category , check out the developer reference.

Vignesh
  • 10,205
  • 2
  • 35
  • 73
  • Thanks! I didn't realize it is a category... I was searching through the net and tearing my hair out and finally :D – cojoj Jul 18 '13 at 09:43
  • I have one more question. Is it possible to modify this category not to save this photos to Camera Roll? Only custom album. – cojoj Jul 18 '13 at 10:17
  • @Cojoj. You are welcome. Its not possible.All image will be stored in camera roll. You can't stop that. – Vignesh Jul 18 '13 at 10:38
0

Look at here:

http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/

And there is a Stackoverflow Thread here: Save Photos to Custom Album in iPhones Photo Library

Community
  • 1
  • 1
Mir23
  • 39
  • 1
  • 7
0

If you are using AssetsLibrary you can write this code

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIImagePickerController *imagePicker;

    if (buttonIndex < 2)    
    {           
        self.library = [[[ALAssetsLibrary alloc] init] autorelease];
        
        self.imageEditor = [[[DemoImageEditor alloc] initWithNibName:@"DemoImageEditor" bundle:nil] autorelease];
        
        self.imageEditor.doneCallback = ^(UIImage *editedImage, BOOL canceled){

            if(!canceled)
            {
                anotherImage = true;
                
                NSString *imageName;
               
                imageName =@"Abc.jpg";
                
                UIImageWriteToSavedPhotosAlbum(editedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);      

                editedImage = [self scaleImage:editedImage toSize:CGSizeMake(600,600)];

                 [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(editedImage)forKey:@"image"];

}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
    
        if (error)

        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];

    else 

        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];

    [alert release];
}

It will solve your case.

Maulik
  • 19,348
  • 14
  • 82
  • 137
Ankur
  • 98
  • 2
  • 13