我想在用户取消电子邮件时发出提醒。为此,我使用以下代码:
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
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)
}
controller.dismiss(animated: true, completion: nil)
}
调用该函数并解除Mail View,但不显示警报。我在UITableViewController中使用此代码。请有人帮帮我吗?
答案 0 :(得分:1)
在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)
}
})
像这样......