这是我的代码,每次按下按钮时都会调用它,但问题是它不会显示视图控制器,而是在控制台中显示如下所示的消息。
func showEmail() {
if MFMailComposeViewController.canSendMail() {
let toRecipents = "Something"
let emailTitle = "Something"
let messageBody = "SOmeting"
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setToRecipients(toRecipents)
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
present(mc, animated: true, completion: nil)
} else {
print("cannot send mails")
}
}
//check if email has been sent
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
switch result.rawValue {
case MFMailComposeResult.cancelled.rawValue:
print("Mail cancelled")
case MFMailComposeResult.saved.rawValue:
print("Mail saved")
case MFMailComposeResult.sent.rawValue:
print("Mail sent")
case MFMailComposeResult.failed.rawValue:
print("Failed to send: \(error)")
default: break
}
dismiss(animated: true, completion: nil)
}
这是我的控制台输出:
[MC] Filtering mail sheet accounts for bundle ID: ------.---------, source account management: 1
[MC] Result: NO
cannot send mails