The MFMailComposeViewController
cannot be dismissed after pressing cancel or send button. I have added MFMailComposeViewControllerDelegate
in my class but still, it's not working?
Here is my code:
func sendEmail() {
let MailVC = MFMailComposeViewController()
MailVC.mailComposeDelegate = self
MailVC.setToRecipients(["\(emailLabel?.text)"])
MailVC.setSubject("Set your subject here!")
MailVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(MailVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
Delegate method signature is wrong. You are missing _
before controller
parameter. Try this.
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
And make sure this.
class ViewController: UIViewController ,MFMailComposeViewControllerDelegate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With