Cannot write(add UIImage) to photo album
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 save开发者_如何学运维d the UIImage to the photo album?
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];
}
精彩评论