简体   繁体   中英

MFMailComposeViewController is not dismissing - Swift, Xcode

I'm currently trying to implement MFMailComposeViewController . Everything is working fine, except after sending an email or clicking cancel, the MFMailComposeViewController does not dismiss. I've looked at similar StackOverflow threads and attempted to implement those solutions, but they have not resolved my issue. I feel like the issue may not lie within the func mailComposeController , but within the rest of my code. Any help would be greatly appreciated.

My code:

   if MFMailComposeViewController.canSendMail() {
        let vc = MFMailComposeViewController()
        vc.delegate = self
        vc.mailComposeDelegate = self
        vc.setSubject("Contact Us/Feedback")
        vc.setToRecipients(["test@gmail.com"])
        present(vc, animated: true)
    }
    else {
        if let url = URL(string: "https://www.google.com") {
        let safariVC = SFSafariViewController(url: url)
                
        present(safariVC, 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)
    }
}

Thanks!

Change

func mailComposeController(controller: MFMailComposeViewController,
     didFinishWithResult result: MFMailComposeResult, error: NSError?) {

To

func mailComposeController(_ controller: MFMailComposeViewController, 
     didFinishWith result: MFMailComposeResult, error: Error?) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM