MFMailComposeViewController,Swift 4,Xcode 9

ĐorđeNilović

我对MFMailComposeViewControllerDelegate函数有问题。

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}

警告说

实例方法'mailComposeController(:didFinishWith:error :)'与协议'MFMailComposeViewControllerDelegate'的可选要求'mailComposeController(:didFinishWith:error :)'几乎匹配

将'mailComposeController(_:didFinishWith:error :)'设为私有以使此警告静音

单击取消后,我需要将用户返回到App并关闭MFMailComposeViewController,并且不会触发此功能。

是的,我添加了代表 composeVC.mailComposeDelegate = self

如果有人遇到类似问题,我将不胜感激。谢谢

编辑

仅当我将语言设置为Swift 4时,才会发生这种行为。我刚刚退回了几次提交,并且在Swift 3.2中工作得很好。

基本上,这是代码:

class TechSupportVC: UIViewController, MFMailComposeViewControllerDelegate {
    let composeVC = MFMailComposeViewController()

override func viewDidLoad() {
    super.viewDidLoad()

    composeVC.mailComposeDelegate = self
    composeVC.setToRecipients(["[email protected]"])
    composeVC.setSubject("My message")
}

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}

@IBAction func sendPressed(_ sender: Any) {
    guard MFMailComposeViewController.canSendMail() else {
        showMailServiceErrorAlert()
        return
    }

    composeVC.setMessageBody("Test credentials: \(firstAndLastNameTextField.text!)\nPhone: \(numberTextField.text!)\n\n\(messageTextView.text!)", isHTML: false)

    self.present(composeVC, animated: true, completion: nil)
}

}

鲍里斯(Boris Y.)

我不可能应用Đorđe的解决方案,另一个答案对我有所帮助。

func mailComposeController(_ controller: MFMailComposeViewController,
                           didFinishWith result: MFMailComposeResult,
                           error: Swift.Error?) {
    controller.dismiss(animated: true, completion: nil)
}

添加Swift.前缀即可Error?解决该问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章