关闭MFMailComposeViewController会导致EXC_BAD_ACCESS [英] Dismissing a MFMailComposeViewController causes EXC_BAD_ACCESS

查看:132
本文介绍了关闭MFMailComposeViewController会导致EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示一个MFMailComposeViewController如下:

   - (IBAction)contactUs:(id)sender {
[Tracker trackContactUsPressed:[MFMailComposeViewController canSendMail]];

if([MFMailComposeViewController canSendMail] == NO){
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@电子邮件错误
消息:@已在此设备上配置,请发送电子邮件至\\\
FOO@BAR.com
委托:self
cancelButtonTitle:@OK
otherButtonTitles:nil];
[alert show];
[alert release];
} else {

MFMailComposeViewController * controller = [[[MFMailComposeViewController alloc] init] autorelease];

[controller setSubject:@关于FOO的评论];

[controller setToRecipients:[NSArray arrayWithObject:@FOO@BAR.com]];
[controller setMailComposeDelegate:self];

[[self parentViewController] presentModalViewController:controller animated:YES];
}
}

然后我的委托看起来像这样:

   - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[ [self parentViewController] dismissModalViewControllerAnimated:YES];
}

然而,一旦委托被调用,视图消失,一个EXC_BAD_ACCESS。回溯描述为:

 #0 0x00000000 in? ()
#1 0x0065a2d9中 - [UIWindowController transitionViewDidComplete:fromView:toView:()
#2 0x0044a905中 - [UITransitionView notifyDidCompleteTransition:()
#3 0x003f1499在 - [UIViewAnimationState sendDelegateAnimationDidStop :完成:()
#4 0x003f132b中 - [UIViewAnimationState animationDidStop:完成:()
#5 0x02631db0在run_animation_callbacks()
#6 0x02631c6f在CA :: timer_callback()
#7 0x0284bf73在__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__()
#8 0x0284d5b4在__CFRunLoopDoTimer()
#9 0x027a9dd9在__CFRunLoopRun()
#10 0x027a9350在CFRunLoopRunSpecific()
#11 0x027a9271在CFRunLoopRunInMode()
#12 0x0305500c在GSEventRunModal()
在UIApplicationMain在GSEventRun#13 0x030550d1()
#14 0x003cfaf2()
#15 0x000023c5主(ARGC = 1 ,argv = 0xbfffefcc)at main.m:14

我似乎无法找出错误。据我所知,这以前与我们使用的3.x SDK(我们发布它和一切!)。现在使用新的SDK(4.1)似乎失败。

解决方案



有人知道发生了什么问题吗? div>

我发现了问题。



我们使用一个名为ShareKit的库来做一些Twitter和Facebook集成。由于我们已经有了自己的电子邮件表单,我们不需要ShareKit为我们处理它,所以我们删除了ShareKit的电子邮件处理文件。



一切都很好,除非在其初始化,ShareKit做到这一点:

  SHKSwizzle([MFMailComposeViewController类],@selector(viewDidDisappear :),@selector( SHKviewDidDisappear :)); 



在哪里SHKSwizzle基本上取代了MFMailComposerViewController的viewDidDisappear:法SHKviewDidDisappear:(不要问我为什么?我认为这太可怕了。)



无论如何,事实证明SHKviewDidDisappear是在ShareKit的邮件处理程序,所以删除文件如何使代码跳到超空间和崩溃可怕。



感谢大家的帮助!

感谢大家的帮助!

I'm displaying a MFMailComposeViewController like so:

- (IBAction) contactUs: (id) sender {
    [Tracker trackContactUsPressed: [MFMailComposeViewController canSendMail]];

    if ([MFMailComposeViewController canSendMail] == NO) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Email Error"
                                                        message: @"Email has not been configured on this device.  Please send us an email at\nFOO@BAR.com"
                                                       delegate: self
                                              cancelButtonTitle: @"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    } else {

        MFMailComposeViewController *controller = [[[MFMailComposeViewController alloc] init] autorelease];

        [controller setSubject:@"Comments about FOO"];            

        [controller setToRecipients: [NSArray arrayWithObject: @"FOO@BAR.com"]];
        [controller setMailComposeDelegate: self];

        [[self parentViewController] presentModalViewController:controller animated:YES];
    }
}

Then my delegate looks like this:

- (void) mailComposeController: (MFMailComposeViewController *) controller didFinishWithResult: (MFMailComposeResult) result error: (NSError *) error {
    [[self parentViewController] dismissModalViewControllerAnimated: YES];
}

However as soon as the delegate is called, and the view disappears, I get a EXC_BAD_ACCESS. The backtrace says this:

#0  0x00000000 in ?? ()
#1  0x0065a2d9 in -[UIWindowController transitionViewDidComplete:fromView:toView:] ()
#2  0x0044a905 in -[UITransitionView notifyDidCompleteTransition:] ()
#3  0x003f1499 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
#4  0x003f132b in -[UIViewAnimationState animationDidStop:finished:] ()
#5  0x02631db0 in run_animation_callbacks ()
#6  0x02631c6f in CA::timer_callback ()
#7  0x0284bf73 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#8  0x0284d5b4 in __CFRunLoopDoTimer ()
#9  0x027a9dd9 in __CFRunLoopRun ()
#10 0x027a9350 in CFRunLoopRunSpecific ()
#11 0x027a9271 in CFRunLoopRunInMode ()
#12 0x0305500c in GSEventRunModal ()
#13 0x030550d1 in GSEventRun ()
#14 0x003cfaf2 in UIApplicationMain ()
#15 0x000023c5 in main (argc=1, argv=0xbfffefcc) at main.m:14

I can't seem to figure out what's wrong. As far as I know, this worked previously with the 3.x SDK we were using (we released it and everything!). Now with the new SDK (4.1) it seems to fail. I'm not sure if that's related.

Does anyone know what's wrong?

解决方案

I found the problem.

We're using a library called ShareKit to do some Twitter and Facebook integration. Since we already had our own email form, we didn't need ShareKit to handle it for us, so we deleted the ShareKit's email handling files.

All was well, except that in its initialization, ShareKit does this:

SHKSwizzle([MFMailComposeViewController class], @selector(viewDidDisappear:), @selector(SHKviewDidDisappear:)); 

Where SHKSwizzle basically replaces MFMailComposerViewController's viewDidDisappear: method with SHKviewDidDisappear: (Don't ask me why... I think that's horrible).

Anyway, it turns out that SHKviewDidDisappear was in ShareKit's mail handler, so deleting the file how makes the code jump to hyperspace and crash horribly. Restoring the file again fixes the problem.

Ugh.

Thanks everyone for your help!

这篇关于关闭MFMailComposeViewController会导致EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆