Pergunta

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!?

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top