MFMailComposeViewController,Swift 4,Xcode 9

编程入门 行业动态 更新时间:2024-10-27 18:22:01
本文介绍了MFMailComposeViewController,Swift 4,Xcode 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对MFMailComposeViewControllerDelegate函数有问题.

I have a problem with MFMailComposeViewControllerDelegate function.

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

警告说

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

Instance method 'mailComposeController(:didFinishWith:error:)' nearly matches optional requirement 'mailComposeController(:didFinishWith:error:)' of protocol 'MFMailComposeViewControllerDelegate'

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

Make 'mailComposeController(_:didFinishWith:error:)' private to silence this warning

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

I need to return the user to the App and dismiss MFMailComposeViewController after clicking cancel and this function is not triggered.

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

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

If someone had a similar problem, I would appreciate the help. Thanks

编辑

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

This behavior is happening only when I set the language to Swift 4. I just went back few commits and it's working perfectly fine with Swift 3.2

基本上,这是代码:

class TechSupportVC: UIViewController, MFMailComposeViewControllerDelegate { let composeVC = MFMailComposeViewController() override func viewDidLoad() { super.viewDidLoad() composeVC.mailComposeDelegate = self composeVC.setToRecipients(["desiredEmail@gmail"]) 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) }

}

推荐答案

我无法应用Đorđe的解决方案,这其他答案帮助了我.

It wasn't possible for me to apply Đorđe's solution, this other answer helped me.

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

在Error?上添加Swift.前缀即可解决此问题.

Adding Swift. prefix to Error? solves the problem.

更多推荐

MFMailComposeViewController,Swift 4,Xcode 9

本文发布于:2023-11-26 06:11:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632946.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MFMailComposeViewController   Swift   Xcode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!