MFMailComposeViewController delegate does not handle CANCEL button

Possible duplicate:
The action table does not appear when you click the cancel button MFMailComposeViewController

I implemented the standard mail functionality in my application according to the sample code provided by Apple.

I configure the delegate as follows:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; 

and I realize

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

Pressing the submit button invokes the delegate and everything works fine. However, clicking the Cancel button does not invoke the delegate, and it simply reduces the presentation; the application hangs right there.

After reading such topics here, I thought that the idea for some reason could be off-screen, which at the moment is beyond understanding. Note that the view is created programmatically and does not use the xib file.

Any thoughts or ideas?

+4
source share
3 answers

You need to implement the delegate mailComposeController:didFinishWithResult:error . And in this you reject the view displaying your inbox. If you opened the mailbox as modalView, then the way to reject this is

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]); [self dismissModalViewControllerAnimated:YES]; return; } 
+9
source

You might be useful

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { // Notifies users about errors associated with the interface switch (result) { case MFMailComposeResultCancelled: //NSLog(@"Result: canceled"); break; case MFMailComposeResultSaved: //NSLog(@"Result: saved"); break; case MFMailComposeResultSent: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; [alert release]; } break; case MFMailComposeResultFailed: //NSLog(@"Result: failed"); break; default: //NSLog(@"Result: not sent"); break; } [self dismissModalViewControllerAnimated:YES]; } 
+8
source

Try adding even a simple delegate:

 [picker setDelegate:self]; 
0
source

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


All Articles