Reject mailComposeController

I try to delete mail from my application after it is completed, if the user sends or cancels. But for some, this does not cancel. I have tried almost everything. I also registered this, so I'll see if he went for the dissmiss method. And the problem is that he never introduces a method of dismissal.

What am I doing wrong?

- (IBAction)sendmail:(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]; mailComposer.delegate = self; [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"]; [mailComposer setSubject:@"Hello from My App!"]; NSString *emailBody = @"Sent from My App, Still not in AppStore!"; [mailComposer setMessageBody:emailBody isHTML:YES]; [self presentModalViewController:mailComposer animated:YES]; } } -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [self dismissModalViewControllerAnimated:YES]; NSLog (@"mail finished"); // NEVER REACHES THIS POINT. } 
+4
source share
3 answers

you can replace this line:

 [self dismissModalViewControllerAnimated:YES]; 

with the following line:

 [controller dismissModalViewControllerAnimated:YES]; 
+4
source

MFMailComposeViewController class inherits from the UINavigationController , and therefore its delegation property is the "delegate" to the controller "part" of the class. To handle certain methods of the mail composer delegate, you need to set your object as the mailComposeDelegate property:

 mailComposer.mailComposeDelegate = self; 
+3
source

SWIFT 5.0:

If you implement the MFMailComposeViewControllerDelegate protocol, you will only need to contain the following function in the ViewController:

 func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) } 

This function handles everything for you. If the user sends an email, the view automatically disappears. Any additional information: mailComposeController

0
source

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


All Articles