【问题标题】:MFMailComposeViewController is not dismissing - Swift, XcodeMFMailComposeViewController 没有解散 - Swift,Xcode
【发布时间】:2020-11-25 00:01:37
【问题描述】:

我目前正在尝试实现MFMailComposeViewController。一切正常,除了发送电子邮件或单击取消后,MFMailComposeViewController 不会关闭。我查看了类似的 StackOverflow 线程并尝试实现这些解决方案,但它们并没有解决我的问题。我觉得问题可能不在于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)
    }
}

谢谢!

【问题讨论】:

    标签: ios swift xcode mfmailcomposeviewcontroller


    【解决方案1】:

    改变

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

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

    【讨论】:

    • 另外,删除vc.delegate = self,因为它什么都不做。
    • 嗨,马特,我已经实现了这个编辑,但是,它并没有解决我的问题。 MFMailComposeViewController 仍然没有关闭。我也删除了 vc.delegate = self 谢谢
    • 哦,使用整个方法,包括两个花括号,剪切它,然后将它粘贴到类声明的顶层。你已经将它写在另一个方法中,它永远不会被调用。
    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 2019-10-10
    • 1970-01-01
    相关资源
    最近更新 更多