tags:

views:

22

answers:

1

I have the following code

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

NSLog(@"failed");
}

which checks for the error, and it prints out time I run the following

-(IBAction) addWallpaper{

UIImageWriteToSavedPhotosAlbum( [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]]
                               , self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
}

How do I correctly saved the UIImage to the photo album?

+1  A: 

Despite the name

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
                               contextInfo:(void *)contextInfo

doesn't indicate an error. You need to check the error passed to this function.

Something like:

-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error
                                  contextInfo:(void*)contextInfo
{
    UIAlertView *alert;
    if ( [error code] != 0 )
    {
            alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                       message:@"Things went wrong!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    } else {
            alert = [[UIAlertView alloc] initWithTitle:@"Great"
                       message:@"Image was saved!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    }
    [alert show];
    [alert release];
}
mvds
Great, thanks. and I also should have thought that it could, maybe it will always? error in the simulator, but runs differently on device, it worked great. Thanks
alJaree
glad it helped. the simulator does have an album so it should work. maybe it depends on SDK version.
mvds