Question

I am developing an app that runs on all the deployment target simulators (5.0-6.1) and on my iPhone 3GS, 4, 4S and a gen 2 iPad. I had the opportunity today to try running it on an iPad Mini. I works everywhere except when I try to segue to a MFMailComposeViewController object to send an email, which causes it to crash with an exception.

I use the code directly from the MailComposer sample project, but it always crashes when it calls presentModalViewController:animated:. So I tried presentViewController:animated:completion: as the other method is deprecated, but it still doesn't work.

I linked to MessageUI.framework imported the classes:

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

The delegate is set. Here is the code:

-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Contact Email"];

    // Set up recipient
    NSArray *toRecipients = [NSArray arrayWithObject:@"info@foo.bar"];
    [picker setToRecipients:toRecipients];

    //  [self presentModalViewController:picker animated:YES];
    [self presentViewController:picker animated:YES completion:NULL];
}

Might there be a bug causing this in the iPad Mini? I don't have any other new devices I can try it on so I'm not sure if its a Mini problem or something bigger. Any help would be appreciated as I'm ready to submit to Apple but I sure don't want to do that with a crashing bug.

Was it helpful?

Solution

It's likely that a mail account has not been set up or for some other reason cannot send email.

Be sure to call the + (BOOL)canSendMail function of MFMailComposeViewController first.

OTHER TIPS

Try wrapping your MFMailComposeViewController code with

if ( [MFMailCompseViewController canSendMail])

I'd guess the device doesn't have mail setup on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top