我想在用户取消电子邮件时显示警报。为此,我使用以下代码:
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)
}
将调用该函数并关闭邮件视图,但不显示警报。我在UITableViewController中使用此代码。有人能帮我吗?
最佳答案
在完成块中显示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)
}
})
这样地。。
关于ios - MFMailComposeViewController didFinishWith结果中的Swift显示警报,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42040013/