ios: Application tried to present a nil modal view controller on target

Forgetting Mail account configuration in device settings may also lead to this error. Re check whether a mail account is configured in your device or not.


Swift 4 version

guard MFMailComposeViewController.canSendMail() else {
    print("Mail services are not available")
    return
}
sendEmail()

As per Apple, You should check is MFMailComposeViewController are able to send your mail just before sending

if ([MFMailComposeViewController canSendMail]) {
     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Test mail"];
    [picker setMessageBody:messageBody.text isHTML:YES];
    [self presentViewController:picker animated:YES completion:NULL];
}

Swift:

if MFMailComposeViewController.canSendMail() else {
// Send mail code
}

Ref : Apple Dev url