0

This is my code I call it every time a button is pressed but the problem is that it does not present the view controller but instead give me the message as shown below in the console.

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)
}

This is my console output:

[MC] Filtering mail sheet accounts for bundle ID: ------.---------, source account management: 1
[MC] Result: NO
cannot send mails
SH_
  • 266
  • 2
  • 3
  • 17
James Lim
  • 83
  • 5

0 Answers0