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

前端 未结 2 1971

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:24

    You need to make your view controller the MFMailComposeViewController delegate and override the method didFinishWith result and switch MFMailComposeResult value inside the completion handler of the dismiss method :

    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true) { 
            // do whatever you need to do after dismissing the mail window
            switch result {
                case .cancelled: print("cancelled")
                case .saved:     print("saved")
                case .sent:
                    let alert = UIAlertController(title: "Mail Composer", message: "Mail was successfully sent", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
                    self.present(alert, animated: true)
                case .failed:    print("failed")
            }
        }
    }
    

提交回复
热议问题