Swift电子邮件作曲家无法正常工作

时间:2017-02-25 20:53:20

标签: ios swift mfmailcomposer

这是我的代码,每次按下按钮时都会调用它,但问题是它不会显示视图控制器,而是在控制台中显示如下所示的消息。

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

0 个答案:

没有答案