【发布时间】:2015-01-07 08:03:44
【问题描述】:
我有这个简单的功能可以在 ios 8.0、xcode 6.1 上写邮件。没什么特别的,它一直工作到 ios 8.0 打招呼。 当一个按钮被点击(通过故事板设置)时,函数 sendMail 会发送一封邮件。我对其进行了调试,代码看起来还可以,但是当您应该返回主应用程序时,它会崩溃并出现 EXC_BAD_ACCESS code=1 错误,例如当您点击 MFMailComposeViewController 的发送或关闭按钮时。在我看来,我的视图,我的意思是调用 MFMailComposeViewController 的视图在调用 MFMailComposeViewController 时被释放,因此当它被解雇时,没有什么可返回的。解决问题的一些想法? [函数 didFinishWithResult 从未到达:崩溃发生在之前。]
编辑:准确地说,如果在 presentViewController 中我将动画设置为 NO,它会因 bad_access 而崩溃。如果是,它会抱怨“开始/结束外观转换的不平衡调用”并且点击发送/关闭什么都不做(它不会返回。邮件视图是活动的,但点击按钮什么都不做)
编辑:我对解除分配是正确的。他有同样的问题,但似乎没有有效的解决方案MFMailComposeViewController crash in iOS6 ARC 在我的情况下,Arc 已关闭,由于各种原因我无法打开它。僵尸仪器证实了这一理论。它说“一个 Objective-C 消息已发送到地址为:0x14e01720 的已释放“视图”对象(僵尸)”
View.h
included MFMailComposeViewControllerDelegate and imported
#import <MessageUI/MFMailComposeViewController.h>
View.m
-(IBAction)sendEmail:(id)sender{
NSString *mailDiretta=emailText.currentTitle;
composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:mailDiretta, nil]];
[composer setSubject:@"Infos"];
[composer setMessageBody:@"Write to me, dude!" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:composer animated:YES completion:NULL];
[composer release];
} else
[composer release];
}
// function below is never reached
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error"
message:[NSString stringWithFormat:@"error %@", [error description]]
delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
[alert show];
[self dismissViewControllerAnimated:YES completion:NULL];
} else {
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
【问题讨论】:
-
它在哪一行崩溃?解雇?
-
它不会在我的代码上崩溃。发送邮件的视图被调用,但是当你点击发送/关闭,而不是返回并执行 didFinishWithResult 时,它崩溃了。
标签: ios objective-c iphone