如何让我的应用打印“'E-Mail send'”或“电子邮件已取消”?
How do I get my app to print ''E-Mail send'' or ''E-Mail cancelled"?
我有一个可以发送电子邮件的应用程序。我已经知道了,因为邮件控制器在发送或取消按钮上键入后关闭。但我想在应用程序中添加一个“'Popup'”或其他内容,告诉用户他们是已发送邮件还是已取消邮件。
注释掉的代码是我尝试让应用程序说出来的,但由于一些警告而无法运行。
@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()
}
在 completionBlock 中显示 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)
}
})
邮件发送方式相同
我有一个可以发送电子邮件的应用程序。我已经知道了,因为邮件控制器在发送或取消按钮上键入后关闭。但我想在应用程序中添加一个“'Popup'”或其他内容,告诉用户他们是已发送邮件还是已取消邮件。
注释掉的代码是我尝试让应用程序说出来的,但由于一些警告而无法运行。
@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()
}
在 completionBlock 中显示 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)
}
})
邮件发送方式相同