使用 MFMailComposeViewController 发送邮件,得到“EXC_BAD_ACCESS”;当关闭模态视图控制器时
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该死,我自己修好了:-)
在发送/取消之前,我在消息正文中释放了一个对象。我修复它的方法是声明这个 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...