IOS mail composer won't quit

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.

+6
source share
2 answers

Try

 mailComposer.mailComposeDelegate = self; 

instead

 mailComposer.delegate = self; 

From the MFMailComposeViewController Documentation :

 @property(nonatomic,assign) id<MFMailComposeViewControllerDelegate> mailComposeDelegate; 

The delegate object is responsible for rejecting the view represented by this view controller at the appropriate time. Therefore, you should always provide a delegate, and this object must implement the methods of the MFMailComposeViewControllerDelegate protocol.

+17
source

I'm sure the last line should be

 [self dismissModalViewControllerAnimated:YES]; 

The ViewController, which introduced the view in models, also rejects it.

+2
source

Source: https://habr.com/ru/post/920229/


All Articles