Search code examples
objective-cios6

MFMailComposeViewController won't dismiss on iOS 6


In iOS 6 the presented MFMailComposeViewController will not dismiss if user attempts to send second email...

Everything works perfectly the first go around and email is sent. However, if email option is selected again the MFMailComposeViewController will not dismiss on cancel.

Here is how I implemented it:

- (IBAction)buttonEmailClick:(id)sender {
    if (![MFMailComposeViewController canSendMail]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Can't send" message:@"This device is unable to send emails." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        return;
    }
    NSDictionary *contactsInfo = [self contactsInfoFromPlistNamed:kConfigPlistName];
    [mailComposeViewController setToRecipients:[NSArray arrayWithObject:[contactsInfo objectForKey:@"email"]]];
    //[mailComposeViewController setSubject:kEmailDefaultSubject];
    //[mailComposeViewController setMessageBody:text isHTML:NO];
    [self presentModalViewController:mailComposeViewController animated:YES];
}

and then this:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    UIAlertView *alert = nil;
    if (result == MFMailComposeResultSent) {
        alert = [[UIAlertView alloc] initWithTitle:@"Sent" message:@"Your email was sent." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    }
    else if (result == MFMailComposeResultFailed) {
        alert = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"An error occured and your email was not sent." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    }

    [alert show];
    [self dismissModalViewControllerAnimated:YES];
}

It works fine in iOS 5 but not in iOS 6. I have tried replacing with non deprecated methods for iOS 6, but it doesn't work.


Solution

  • Have you tried creating a fresh MFMailComposeViewController each time they go to send an email? I'm not sure if you should be reusing it.