您应该在尝试发送邮件之前检查 MFMailComposeViewController 是否能够发送您的邮件(例如,用户在 iOS 设备上可能没有任何邮件帐户)。
所以在你的Objective-C的情况下:
MFMailComposeViewController *myMailCompose = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail]) {
myMailCompose.mailComposeDelegate = self;
[myMailCompose setSubject:@"Subject"];
[myMailCompose setMessageBody:@"message" isHTML:NO];
[self presentViewController:myMailCompose animated:YES completion:nil];
} else {
// unable to send mail, notify your users somehow
}
斯威夫特 3:
let myMailCompose = MFMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
myMailCompose.mailComposeDelegate = self
myMailCompose.setSubject("Subject")
myMailCompose.setMessageBody("message", isHTML: false)
self.present(myMailCompose, animated: true, completion: nil)
} else {
// unable to send mail, notify your users somehow
}