Question

I am trying to check if an Email message was sent and display an Alert allowing the user know.
I tried the delegate method below , but sadly will display the alert message if user cancels as well. Any help will be appreciated and rewarded.

 - (void)mailComposeController:(MFMailComposeViewController*)controller
      didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:
                                   [NSString stringWithFormat:@"Error %@", [error description]] delegate:self
                                                   cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];
}


     NSLog(@"email sent");
    }

}
Was it helpful?

Solution

All that it means when that function is called is that something happened with the email because the MFMailComposeViewController is finished. To know what did actually happen, you have to take a look at the value of result, which can be any of the following:

MFMailComposeResultCancelled
MFMailComposeResultSaved
MFMailComposeResultSent
MFMailComposeResultFailed

As rmaddy says in comments, you can't be 100% sure that the email was actually sent (it could be stuck in the outbox). What MFMailComposeResultSent signifies, then, is that the email has been sent over to the Mail app, which will send it as soon as it can.

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