iOS: App crash "-[MFMailComposeInternalViewController _notifyCompositionDidFinish]"

5

according to crashlytic someone crash while using the iPad. The crash error they received is -[MFMailComposeInternalViewController _notifyCompositionDidFinish] I don't know how this could've occurred. Here is the exception Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000c

Here is the raw data

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x30fa4f46 objc_msgSend + 5
1  MessageUI                      0x252e5f01 -[MFMailComposeInternalViewController _notifyCompositionDidFinish] + 464
2  CoreFoundation                 0x23524294 __invoking___ + 68
3  CoreFoundation                 0x23451435 -[NSInvocation invoke] + 300
4  libdispatch.dylib              0x314f87bb _dispatch_call_block_and_release + 10
5  libdispatch.dylib              0x314f87a7 _dispatch_client_callout + 22
6  libdispatch.dylib              0x314fbfa3 _dispatch_main_queue_callback_4CF + 718
7  CoreFoundation                 0x234e59d1   __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
8  CoreFoundation                 0x234e40d1 __CFRunLoopRun + 1512
9  CoreFoundation                 0x23432211 CFRunLoopRunSpecific + 476
10 CoreFoundation                 0x23432023 CFRunLoopRunInMode + 106
11 GraphicsServices               0x2a7c20a9 GSEventRunModal + 136
12 UIKit                          0x26a3e1d1 UIApplicationMain + 1440
13 MyApp                          0x0009e7e7 main (main.m:16)

Not sure how I can diagnose it.

ios
objective-c
crash
mfmailcomposeviewcontroller
unrecognized-selector
asked on Stack Overflow Nov 20, 2014 by Wizard Lizard • edited Nov 20, 2014 by Wizard Lizard

3 Answers

3

This crash happens when MFMailComposeInternalViewController object released and MFMailComposeInternalViewControllerDelegate fired.

Make sure to retain your MFMailComposeInternalViewController object until following delegate fire and then you can safely dismiss the MFMailComposeInternalViewController object.

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            break;
        case MFMailComposeResultSent:
            break;
        case MFMailComposeResultFailed:
            break;
        default:
            break;
    }
    [controller dismissViewControllerAnimated:YES completion:nil];
}
answered on Stack Overflow Oct 26, 2015 by Charitha Basnayake
0

Recently I have faced this crash and have an explanation about this crash. Consider you have a ViewController and you confirmed the Mail Composer delegate to it. After presenting the Mail Composer, the ViewController get de-initilize (with some reason) and what happened after this is, the Mail Composer try to communicate with the presented view controller that is not exist in the memory.

Im using container view and in UITableViewCell (Each cell having a UIViewController as a child and Im using to clear the cell content when didEndDisplying), here when I present the Mail Composer from My ViewController (It is embedded in UITableViewCell) the didEndDisplay tableView Delegate is getting called because of this my ViewController (embedded in table view cell) is getting removed from the memory, so the confirmed mailComposerDelegates are not there on that time, if I send/Cancel any action on the presented Mail Composer View is giving me the crash.

To fix the issue, I have removed the code (clearing cell content from did end displaying table view delegate method).

To confirm this, please put a break point at deinit() in your view controller where you use to present the MailComposer.

Sorry for my bad English.

0

Finally fixed this, but mine case was extremely strange.

On iPhone 6s iOS 13.3.1 everything worked perfectly. User could open mail and dismiss it without any problems.

On another iPhone8 also iOS 13.3.1 user couldn't close mail composer - he was stuck with it.

On iPhone 6s iOS 12.4 there was that crash [MFMailComposeInternalViewController _notifyCompositionDidFinish]

Turns out that the reason was two ActionViewControllers that were presented by myViewController just before mail composer was showed by the same myViewController and console output showed:

Warning: Attempt to present <UIAlertController: 0x10c819a00>  on <ContactViewController: 0x10d017400> which is already presenting (null)

Somehow it caused class holding MFMailComposeViewController to deinit, but looking at the code it was unrelated to those UIAlertController controllers and still it occurred only on some devices.

So before you present MFMailComposeViewController, make sure that any other view is dismissed before.

answered on Stack Overflow Mar 25, 2020 by gogel

User contributions licensed under CC BY-SA 3.0