Question

this is how my email form looks like:

if ([MFMailComposeViewController canSendMail]) {

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

    [mail setSubject:@"Hello and welcome!"];

    NSArray *toRecipients = [NSArray arrayWithObject:@"email@gmail.com"];
    [mail setToRecipients:toRecipients];
    [mail setCcRecipients:toRecipients];

    NSString *emailBody = @"Hey all!";
    [mail setMessageBody:emailBody isHTML:NO];

    mail.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentViewController:mail animated:YES completion:nil];


} else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                    message:@"E-mail is not supported on your device"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

Emails are sent OK but the problem is, once I hit send button the email is sent but the viewcontroller (or pop up window) does not close. And also close button doesn't work. I simply can't get out from email form.

Any ideas?

Was it helpful?

Solution

You may be not calling

dismissViewControllerAnimated

[self dismissViewControllerAnimated:YES
                         completion:nil];

use this:

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

    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            NSLog(@"mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"mail failed");
            break;
    }
[self dismissViewControllerAnimated:YES
                         completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top