我对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
发布评论