4

Possible Duplicate:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tapped

I've implemented standard mail functionality in my app according to the code sample provided by Apple.

I'm setting up the delegate as follows:

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

and I'm implementing

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

Hitting the Send button invokes the delegate and it all works fine. However, hitting the Cancel button doesn't call the delegate and it just dims the view; the app hangs right there.

After reading similar threads here, I've been thinking that the view could be off-screen for some reason which is beyond my comprehension at this point. Note that the view is being created programmatically and is not using a xib file.

Any thoughts or ideas ?

Community
  • 1
  • 1
user628896
  • 225
  • 2
  • 9
  • If the delegate is not getting called for cancel then one suspects the delegate was not set right, or you've somehow "broken" the environment of the mail controller such that it's taking an error of sorts internally. – Hot Licks Nov 29 '11 at 05:39

3 Answers3

9

You need to implement mailComposeController:didFinishWithResult:error delegate. And in that you dismiss the view which is showing your mail view. If you have opened the mail view as a modalView, then the way to dismiss this is -

- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error 
{ 
    if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
    [self dismissModalViewControllerAnimated:YES];
    return;
}
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
8

It may be helpful to you

- (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];
}
Tendulkar
  • 5,550
  • 2
  • 27
  • 53
0

Try to add even simple delegate :

[picker setDelegate:self];
Andrea Mario Lufino
  • 7,921
  • 12
  • 47
  • 78