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

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:39:27

问题


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:


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



来源:https://stackoverflow.com/questions/2173517/using-mfmailcomposeviewcontroller-to-send-a-mail-get-exc-bad-access-when-dism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!