Airtower Airtower - 1 year ago 101
iOS Question

MFMailComposeViewController not displaying in iOS 8

When I run Xcode 6 and use the iOS 8 simulator, I am trying to load a MFMailComposeViewController, it does not come up. Instead I get this error...

"Warning: Attempt to present MFMailComposeViewController: 0x7c30c400 on ViewController: 0x7baf6000 which is already presenting (null)"

This exact same code has been working for almost a year now, unchanged.
Just to be sure, I ran my app in Xcode 6 with the iOS 7.1 simulator and it worked like before, perfectly.

Does anyone know how to display a MFMailComposeViewController view in iOS 8?
This seems like a simple task and I'm sure its an easy fix.

PS. Posting is NOT needed because it is standard code but here it is anyway...

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

//Current Date
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSDate *date = [NSDate date];
//Ensure UTC DATE
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[formatter setDateFormat:@"MM/dd/yyyy 'at' HH:mm:ss UTC"];
NSString *myString = [formatter stringFromDate:date];

NSString *emailBody = [NSString stringWithFormat:@"Feedback time at %@.<br><br>Name:", myString];
[picker setMessageBody:emailBody isHTML:YES];

NSString *subject, *emailAddress;

[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[formatter setDateFormat:@"MM/dd/yyyy"];
subject = [NSString stringWithFormat:@"Feedback"];

//Set the Subject
[picker setSubject:subject];

emailAddress = @"";

//Set the Receivers
NSArray *myReceivers = [[NSArray alloc] initWithObjects:emailAddress, nil];
[picker setToRecipients:myReceivers];

//It saves the file name as the same as Subject here!
picker.navigationBar.barStyle = UIBarStyleDefault;//UIBarStyleBlack;
[self presentViewController:picker animated:YES completion:^{}];

Answer Source

I was having a similar problem but did not get the same message. However on iOS 8 my Mail Composer would not display. I was launching it from a button on a UIPopover. I would show the Mail Composer and then a few lines of code later I called:

    [myPopover dismissPopoverAnimated:YES];

Another thread on StackOverflow indicated that maybe it had something to do with another view controller being active. So I moved my dismiss popover above the other call to show the Mail Composer and also made it not animated:

    [aboutPopover dismissPopoverAnimated:NO];

Now it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download