MFMailComposeViewController 没有关闭 - Swift、Xcode

MFMailComposeViewController is not dismissing - Swift, Xcode

我目前正在尝试实施 MFMailComposeViewController。一切正常,除了发送电子邮件或单击取消后,MFMailComposeViewController 不会关闭。我查看了类似的 Whosebug 线程并尝试实施这些解决方案,但它们没有解决我的问题。我觉得问题可能不在 func mailComposeController 中,而是在我的其余代码中。任何帮助将不胜感激。

我的代码:

   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)
    }
}

谢谢!

改变

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

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