I am trying to take a screenshot and send it by email using the mail composer. Everything works fine, except that the composer will not be fired. This post seems to have the same problem, but the provided solution did not work for me. Can't dismiss the email composer view on iPhone?
- (IBAction)Email:(id)sender { UIGraphicsBeginImageContext(self.view.frame.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData * imageData = UIImageJPEGRepresentation(image, 1.0); if ( [MFMailComposeViewController canSendMail] ) { MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease]; mailComposer.delegate = self; [mailComposer setSubject:@"Risk Assessment"]; [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"]; [self presentModalViewController:mailComposer animated:YES]; } }
The code above works fine. How can I call this bottom. It seems that the compiler just skips it.
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ if (error){ NSString *errorTitle = @"Mail Error"; NSString *errorDescription = [error localizedDescription]; UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:errorTitle message:errorDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [errorView show]; [errorView release]; } [controller dismissModalViewControllerAnimated:YES]; }
Thanks in advance.
source share