最近新做的項目中有遇到這么一個問題,在客戶手寫繪制好個人簽名后,保存圖片到相冊后,產品說要加個提示框,提示保存照片成功與否。因為這個操作不涉及到后臺,只是移動端設備自身內部的操作,所以接到這個需求,我在想蘋果應該有提供這么一個方法,只是我前面不知道,果然。
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 圖片通過上下文獲得,保存圖片到相冊,注意我的selector函數的寫法,一定要按這個格式來寫,不然會報錯。
> UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (NSString *)str{
NSString *msg = nil ;
if(error != NULL){
msg = @"保存圖片失敗" ;
}else{
msg = @"保存圖片成功" ;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存圖片結果提示"
message:msg
delegate:self
cancelButtonTitle:@"確定"
otherButtonTitles:nil];
[alert show];
}