MFMailComposeViewController 不会关闭



我的应用程序中有以下代码来发送电子邮件:

let ToRecipents = ["recipient here"]
        let subject = "subject here"
        let MessageBody = "message here"
        let mc : MFMailComposeViewController = MFMailComposeViewController()
        mc.mailComposeDelegate = self

        mc.setToRecipients(ToRecipents)
        mc.setSubject(subject)
        mc.setMessageBody(MessageBody, isHTML: false)
        self.present(mc, animated: true, completion: nil)
    }
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
        controller.dismiss(animated: true, completion: nil)
    }

我似乎无法让 MFMailComposeViewController 关闭,我做错了什么?

一般情况下,当不调用委托方法时:
• 检查是否设置了委托。你用mc.mailComposeDelegate = self
正确地做到这一点• 检查您设置的委托方法是否符合协议。
• 检查委托方法是否正确实现(这就是您的问题所在(在您作为委托传递的对象中。阅读文档,或删除方法声明,让编译器/IDE/XCode 为您自动完成它。在 Swift 中,在各种教程之间,它们经常是问题,因为 Swift 1、Swift 2、Swift 3/4 重命名了方法并导致问题,教程只关注 Swift 版本。

您的方法:

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

文档中的方法:

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

由于它们不相同,并且 iOS SDK 应检查委托是否响应正确的方法,因此不应调用你的方法,因为它不匹配。

相关内容

  • 没有找到相关文章

最新更新