Search code examples
iphoneobjective-ciosemailmfmailcomposeviewcontroller

How can I detect when the in-app MFMailComposeViewController has disappeared?


I have set up some code to pull up MFMailComposeViewController so that users of the app can email people from within the app. How can I detect when this view controller has disappeared?

Thanks!


Solution

  • It may be useful to you.Here you can know which button he have pressed.So that you can know the mail composer displayed or not

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
    {   
        // Notifies users about errors associated with the interface
        switch (result)
        {
            case MFMailComposeResultCancelled:
                //NSLog(@"Result: canceled");
                break;
            case MFMailComposeResultSaved:
                //NSLog(@"Result: saved");
                break;
            case MFMailComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
            }
                break;
            case MFMailComposeResultFailed:
                //NSLog(@"Result: failed");
                break;
            default:
                //NSLog(@"Result: not sent");
                break;
        }
        [self dismissModalViewControllerAnimated:YES];
    }