Reputation: 6470
I am able to successfully dismiss my MFMailComposeViewController
in the didFinishWithResult
delegate method. However, I have a scenario where I would like to dismiss the composer without user interaction, like selecting cancel or sending the mail.
I have looked in apple docs and was unable to find anything entirely useful. I have tried calling dismissViewControllerAnimated
but that only seems to be working when I am inside the didFinishWithResult
delegate method. Is there anyway to force that delegate method or dismiss the composer alternatively?
Upvotes: 0
Views: 152
Reputation: 9030
Assuming you are presenting your mail controller from a UIViewController
, you may dismiss it programmatically by calling the UIViewController
method:
dismissViewControllerAnimated:completion:
See this apple reference: dismissViewControllerAnimated:completion:
You did mention:
I have tried calling dismissViewControllerAnimated but that only seems to be working when I am inside the didFinishWithResult delegate method
What you are experiencing may be indicative of a different problem as I was able to successfully do this outside of the mailComposeController:didFinishWithResult:error:
delegate method.
Example:
-(void)showMail
{
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
//Set the message, subject, etc...
//Display
[someViewController presentViewController:mailController animated:YES completion:nil];
//As a proof of concept, close programmatically after a couple of seconds...
[self performSelector:@selector(dismissMailController) withObject:nil afterDelay:2.0];
}
-(void)dismissMailController
{
[someViewController dismissViewControllerAnimated:YES completion:nil];
}
Upvotes: 1