iphone - 线程 1 : EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5. 1、5、4.3)

标签 iphone ios mfmailcomposeviewcontroller exc-bad-access

好吧,这已经困扰我一段时间了......

我已经检查过了,所有其他问题/答案都与非 ARC 项目有关。

每当我展示 MFMCvc 并快速取消消息时,我都会在 iPhone 上收到 Thread1:EXEC_BAD_ACCESS 错误消息。在 iPad 上运行良好,或者如果我让它静置一会儿(比如 30 秒或更长时间)

有什么建议吗? (除了设置一个计时器并且在计时器结束之前不解雇?)

顺便说一句,我对 MFMessageComposeViewController 做同样的事情,它在 iPhone 和 iPad 上都可以正常工作。

这是我展示它的代码

if (([action isEqualToString:@"EMail"]) && contact.length>0)
{
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    if([MFMailComposeViewController canSendMail]) {
        [mailViewController setSubject:@""];
        [mailViewController setMessageBody:@"" isHTML:NO];
        [mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
        [mailViewController setMailComposeDelegate:self];
        [self presentModalViewController:mailViewController animated:NO];
    }
}

这就是我忽略它的地方
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        switch (result)
        {
            case MFMailComposeResultCancelled:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Cancelled"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultFailed:
            {
                NSLog(@"Error");
            }
                break;
            case MFMailComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Sent"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultSaved:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Saved"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            default:
                break;
        }
        [self dismissModalViewControllerAnimated:NO];
    }

最佳答案

1) 行不行:[self dismissModalViewControllerAnimated:NO]; - 需要:[controller dismissModalViewControllerAnimated:NO]; ?您想要关闭 MFMailComposeViewController。

2) MFMailComposeViewController 未保留也可能存在问题。当我使用这个类时,我为 Controller 创建了一个属性。这可能值得一试。

// in the interface definition
 @property (nonatomic, strong) MFMailComposeViewController* mailComposer;

进而
// at creation time
if (([action isEqualToString:@"EMail"]) && contact.length>0)

if(![MFMailComposeViewController canSendMail]) return; // bail early if can't send mail

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
[mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
[mailViewController setMailComposeDelegate:self];
[self presentModalViewController:mailViewController animated:NO];

[self setMailComposer: mailViewController];
// if not using ARC then:  [mailViewController release];

然后在 didFinish
 [[self mailComposer] dismissModalViewControllerAnimated:YES];
 [self setMailComposer: nil];

关于iphone - 线程 1 : EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5. 1、5、4.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655540/

相关文章:

iphone - 如何获取 Facebook 帖子 ID?

iphone - 如何将字符串值从一个.m文件传递到另一个.m文件

ios - PHAsset + AFNetworking。无法在真实设备上将文件上传到服务器

ios - 当我的 iOS 应用程序在后台使用 ReplayKit 时的屏幕录制

ios - NSURLSession 子类化

ios - 无法将caf格式转换为m4a格式

ios - 如果用户尚未设置电子邮件,则要求用户设置电子邮件

iphone - 是否可以向 UIScrollView 添加固定内容?

ios - MFMailComposeViewController 出现一秒钟然后消失

iphone - MFMailComposeViewController 挂起我的应用程序