Reputation: 89
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)
}
Upvotes: 5
Views: 1576
Reputation: 19156
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
Upvotes: 5