john doe
john doe

Reputation: 9660

MFMailComposeViewController Keeps Closing Automatically

This is a really weird issue! I have a button on screen which when pressed launches the MFMailComposeViewController using the following code:

-(IBAction) openComposeEmailScreen:(id) sender {

    if([MFMailComposeViewController canSendMail]) {

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

        [mailComposeViewController setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
        [mailComposeViewController setSubject:@"HelloWorld"];

        NSLog(@"%@",_pasteBoard.string);

        [mailComposeViewController setMessageBody:_pasteBoard.string isHTML:NO];

        [self presentViewController:mailComposeViewController animated:YES completion:nil];
    }
}

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

    if(error) {
        NSLog(@"%@",error.localizedDescription);
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}

Also, my view controller uses the correct protocol:

ViewController ()<MFMailComposeViewControllerDelegate>

I am running this on the simulator.

Upvotes: 1

Views: 130

Answers (1)

Ewan Mellor
Ewan Mellor

Reputation: 6847

MFMailComposeViewController isn't supported in the simulator. You have to run on a device.

Upvotes: 2

Related Questions