Это мой код, который я вызываю каждый раз, когда нажимается кнопка, но проблема в том, что он не представляет контроллер представления, а вместо этого дает мне сообщение, как показано ниже в консоли.
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