Can't close MFMailComposeViewController in Swift 3.0
MFMailComposeViewController
cannot be canceled after clicking the cancel or submit button. I added MFMailComposeViewControllerDelegate
in my class, but still, it doesn't work?
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)
}
+3
source to share
1 answer
Invalid delegate method signature. You are missing _
before the parameter controller
. Try it.
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 of this.
class ViewController: UIViewController ,MFMailComposeViewControllerDelegate
+2
source to share