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

懵懂的女人 提交于 2019-11-28 08:05:58
Toseef Khilji

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];
}

Ref : Apple Dev url


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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!