我有以下代码
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
NSLog(@"failed");
}
检查错误,并打印出运行以下内容的时间
-(IBAction) addWallpaper{
UIImageWriteToSavedPhotosAlbum( [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]]
, self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
}
如何正确保存UIImage到相册?
答案 0 :(得分:1)
尽管有名字
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
不表示错误。您需要检查传递给此函数的error
。
类似的东西:
-(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];
}