Swift 3 How to display a confirmation screen based on MFMailComposeResult email screen

前端 未结 2 1970

I\'m building an app that constructs an email and presents it in a MFMailComposeViewController for the user to send. When the user sends or cancels it I want the app to res

2条回答
  •  一生所求
    2020-11-30 15:27

    If you want to present an alert before the controller is dismissed? Try this one:

    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    
    
        switch result {
        case .cancelled:
    
            let alertController = UIAlertController.init(title: "Cancelled", message: "Some message", 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: "Some message", 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)
    
        default:
            break;
        }
    }
    

提交回复
热议问题