使用 MFMailComposeViewController 发送邮件,得到“EXC_BAD_ACCESS”;当关闭模态视图控制器时

发布于 2024-08-20 06:39:11 字数 1398 浏览 12 评论 0原文

我正在使用 MFMailComposeViewController 从我的 iPhone 应用程序发送电子邮件。这工作正常,但发送或取消后我需要关闭 modalViewController。当我这样做时,我收到程序接收信号:“EXC_BAD_ACCESS”。这不是很描述性...请帮助!

这是创建邮件和 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];   

}

这是委托的代码,忽略了 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];
}

感谢您的帮助!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如若梦似彩虹 2024-08-27 06:39:11

该死,我自己修好了:-)

在发送/取消之前,我在消息正文中释放了一个对象。我修复它的方法是声明这个 body 对象自动释放。你知道什么?有用!

刚刚回答了我自己的问题...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文