Disabling MFMailComposeViewController calls EXC_BAD_ACCESS

I am showing MFMailComposeViewController as follows:

- (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 EXC_BAD_ACCESS. The return stroke says the following:

#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 understand what happened. As far as I know, this worked previously with the SDK 3.x, which we used (we released it and that’s all!). Now with the new SDK (4.1), it seems to be failing. I'm not sure if this is related.

Does anyone know what is wrong?

+4
source share
4 answers

I found a problem.

ShareKit Twitter Facebook. , ShareKit, , ShareKit.

, , ShareKit :

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

SHKSwizzle MFMailComposerViewController viewDidDisappear: SHKviewDidDisappear: ( , ... , ).

, , SHKviewDidDisappear ShareKit, , . .

.

!

+8

, :

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

[[self parentViewController] dismissModalViewControllerAnimated: YES];

, , [self parentViewController] ? (, ); / (, ).

, , , , UINavigationController/UITabBarController, , , .

:

[[self navigationController] presentModalViewController:controller animated:YES]

, , , , , .

? , "" , ?

+1

, - . , UIDocumentInteractionController. , , MFMailComposeViewController , didFinishWithResult.

0

, :

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

, -

And also to represent the composer, Instead of using

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

try using

 [self presentModalViewController:controller animated:YES];
0
source

All Articles