开发者

Using MFMailComposeViewController to send a mail, get “EXC_BAD_ACCESS” when dismissing the modal view controller

开发者 https://www.devze.com 2022-12-19 05:23 出处:网络
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 rec

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!!


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号