MFMailComposeViewController hangs my app

Posted by Neal L on Stack Overflow See other posts from Stack Overflow or by Neal L
Published on 2010-03-11T19:32:57Z Indexed on 2010/03/11 19:34 UTC
Read the original article Hit count: 460

Hi,

I am trying to add email functionality to my app. I can get the MFMailComposeViewController to display correctly and pre-populate its subject and body, but for some reason when the user clicks on the "Cancel" or "Send" buttons in the nav bar the app just hangs. I inserted a NSLog() statement into the first line of mailComposeController"didFinishWithResult:error and it doesn't even print that line out to the console.

Does anybody have an idea what would cause the MFMailComposeViewController to hang like that?

Here is my code from the header:

#import "ManagedObjectEditor.h"
#import <MessageUI/MessageUI.h>

@interface MyManagedObjectEditor : ManagedObjectEditor 
    <MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate,
     UINavigationControllerDelegate> {
}

- (IBAction)emailObject;
@end

from the implementation file:

if ([MFMailComposeViewController canSendMail]) {        
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.delegate = self;
    [mailComposer setSubject:NSLocalizedString(@"An email from me",
                                               @"An email from me")];
    [mailComposer setMessageBody:emailString
                          isHTML:YES];
    [self presentModalViewController:mailComposer animated:YES];
    [mailComposer release];
}
[error release];
[emailString release];

and here is the code from the callback:

#pragma mark -
#pragma mark Mail Compose Delegate Methods
- (void)mailComposeController:(MFMailComposeViewController *)controller 
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError *)error {
    NSLog(@"in didFinishWithResult:");
    switch (result) {
        case MFMailComposeResultCancelled:
            NSLog(@"cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"sent");
            break;
        case MFMailComposeResultFailed: {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error sending email!",@"Error sending email!")
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle:NSLocalizedString(@"Bummer",@"Bummer")
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        }
        default:
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

Thanks!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about mfmailcomposeviewcontroll