解雇MFMailComposeViewController会导致EXC_BAD_ACCESS

Tom*_*zdz 4 iphone crash email-integration

我正在显示一个MFMailComposeViewController,如下所示:

- (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];
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我的代表看起来像这样:

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

但是,只要调用委托,并且视图消失,我就会得到一个EXC_BAD_ACCESS.回溯说:

#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
Run Code Online (Sandbox Code Playgroud)

我似乎无法弄清楚出了什么问题.据我所知,这之前使用的是我们使用的3.x SDK(我们发布了它和所有内容!).现在使用新的SDK(4.1)似乎失败了.我不确定这是否相关.

有谁知道什么是错的?

Tom*_*zdz 8

我发现了这个问题.

我们正在使用一个名为ShareKit的库来进行Twitter和Facebook集成.由于我们已经拥有自己的电子邮件表单,因此我们不需要ShareKit来处理它,因此我们删除了ShareKit的电子邮件处理文件.

一切都很好,除了在初始化,ShareKit这样做:

SHKSwizzle([MFMailComposeViewController class], @selector(viewDidDisappear:), @selector(SHKviewDidDisappear:)); 
Run Code Online (Sandbox Code Playgroud)

SHKSwizzle基本上用SHKviewDidDisappear替换了MFMailComposerViewController的viewDidDisappear:方法:(不要问我为什么......我认为这太可怕了).

无论如何,事实证明SHKviewDidDisappear是在ShareKit的邮件处理程序中,所以删除文件是如何使代码跳转到超空间并崩溃的可怕.再次恢复该文件可以解决问题.

啊.

谢谢大家的帮助!