在应用

时间:2018-05-10 22:51:39

标签: swift xcode9 uialertaction

我想在我点击发送或取消我的电子邮件弹出窗口之后立即显示警报控制器,显示我的邮件是否已发送,我已设法在发送邮件之前显示警报控制器但不是AFTER ......:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {


    switch result {
    case .cancelled:

        let alertController = UIAlertController.init(title: "Cancelled", message: "Send Email has been cancelled", preferredStyle: .alert)
        alertController.addAction(UIAlertAction.init(title: "Ok", style: .default, handler: { (alertAction) in
            controller.dismiss(animated: true, completion: nil)
        }))
        controller.present(alertController, animated: true, completion: nil)

    case .sent:



        let alertController = UIAlertController.init(title: "Sent", message: "Message Sent Successfully", preferredStyle: .alert)
        alertController.addAction(UIAlertAction.init(title: "Ok", style: .default, handler: { (alertAction) in
           controller.dismiss(animated: true, completion: nil)

        }))



    default:
        break;
    }

这就是我试过的

1 个答案:

答案 0 :(得分:0)

问题是你试图使用一个弹出窗口的控制器加上它会被解雇,你可以试试

 UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)