我有一个允许我发送电子邮件的应用程序。我已经知道了,因为在发送或取消按钮上键入后,邮件控制器已关闭。但是我想在应用程序内部安装一个“弹出窗口”或一些东西,告诉用户他们是否发送了邮件或取消了邮件。
注释掉的代码是我尝试让应用程序说出来的,但是由于一些警告,它无法正常工作。
@IBAction func Senden(_ sender: Any) {
let toRecipients = ["Mail@adress.com"]
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setToRecipients(toRecipients)
mc.setSubject(FirmaFeld.text!)
mc.setMessageBody("Firma: \(FirmaFeld.text!) \n\n Kontaktperson: \(KontaktpersonFeld.text!) \n\n EMail: \(EMailFeld.text!) \n\n Anliegen: \(NachrichtFeld.text!)", isHTML: false)
self.present(mc, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Swift.Error?) {
controller.dismiss(animated: true, completion: nil)
}
/* 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("Mail sent failure: %@", [error!.localizedDescription])
default:
break
}
// Dismiss the mail compose view controller.
self.dismiss(animated: true, completion: nil)
}*/
@IBAction func dismissKeyboard(_ sender: Any) {
self.resignFirstResponder()
}
我希望有人能帮忙(对不起英语)。
答案 0 :(得分:0)
希望这对您有帮助
在完成区块内显示alertController。
controller.dismiss(animated: true, completion: {
if result == .cancelled {
let alertController = UIAlertController(title: "E-Mail not sent!", message: "E-Mail not sent.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
}))
present(alertController, animated: true, completion: nil)
}
})
邮件发送方式相同。