Using MFMailComposeViewController to send a mail,

2019-07-30 09:56发布

I am sending an email from my iPhone app using MFMailComposeViewController. This works fine but after sending or canceling I need to dismiss the modalViewController. When I do this I get a Program received signal: “EXC_BAD_ACCESS”. This is not very descriptive... Please help!!

This is the code for creating the mail and the modalViewController

-(void)sendFavMail:(NSString *)body{

    MFMailComposeViewController* mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:@"Favorites List"];
    [mailViewController setMessageBody:body isHTML:YES]; 
    [self presentModalViewController:mailViewController animated:YES];
    [mailViewController release];   

}

And this is the code for the delegate, dismissing the modalviewcontroller:

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error;
{
 switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Cancelled sending");
            break;
        case MFMailComposeResultSaved:
   NSLog(@"Message Saved");
            break;
        case MFMailComposeResultSent:
   NSLog(@"Message Sent");
            break;
        case MFMailComposeResultFailed:
   NSLog(@"Sending Failed");
            break;
        default:
   NSLog(@"Message not sent");
            break;
    } 
[self dismissModalViewControllerAnimated:YES];
}

Thanks for your help!!

1条回答
混吃等死
2楼-- · 2019-07-30 10:42

Darn, fixed it myself :-)

I released an object in the body of the message before sending/cancelling. What I did to fix it is to declare this body object autoreleased. And what do you know? IT WORKS!

Just answered my own question...

查看更多
登录 后发表回答