我刚刚将代码更新为Swift 4.2,并修复了所有错误。现在,我正在尝试使用“ MessageKit”将Messenger放入我的应用程序。一切都已更新,但我遇到了这些问题...现在是说MessagesInputBarDelegate
“使用未声明的类型'MessagesInputBarDelegate'”
和
“使用未声明的类型'MessageInputBar'”
也是
“参数标签'(type :)'与任何可用的重载都不匹配”
和
“无法转换类型'_的值?'预期的参数类型“ URL?”
使用未声明的类型'MessagesInputBarDelegate'
使用未声明类型的“ MessageInputBar”
extension CustomerChatViewController: MessagesInputBarDelegate {
func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {
let message = Message(user: user, content: text)
save(message)
inputBar.inputTextView.text = ""
}
}
参数标签“(类型:)”与任何可用的重载都不匹配
let cameraItem = UIBarButtonItem(type: .system)
无法转换类型“ _?”的值预期的参数类型“ URL?”
let imageName = [UUID().uuidString, String(Date().timeIntervalSince1970)].joined()
storage.child(channelID).child(imageName).putData(data, metadata: metadata) { meta, error in
completion(meta?.downloadURL())
}
答案 0 :(得分:5)
您已安装 MessageInputBar 吗?您可以这样安装
pod 'MessageInputBar'
自 MessageKit 2.0.0 起,您必须安装 MessageInputBar
答案 1 :(得分:1)
然后添加对我也有用
import InputBarAccessoryView
然后在viewDidLoad()中添加以下内容:
override func viewDidLoad() {
super.viewDidLoad()
messageInputBar.delegate = self
maintainPositionOnKeyboardFrameChanged = true
messageInputBar.inputTextView.tintColor = .yellow
messageInputBar.sendButton.setTitleColor(.purple, for: .normal)
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
messagesCollectionView.messageCellDelegate = self
messageInputBar.leftStackView.alignment = .center
messageInputBar.setLeftStackViewWidthConstant(to: 50, animated: false)
}
调用委托方法:
extension ChatVC: MessageInputBarDelegate {
func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
guard let user = self.user else{return}
guard let uid = Auth.auth().currentUser?.uid else{return}
let ref = Database.database().reference().child("messages").child(uid).child("personal").child(user.uid)
let values = ["sender": uid, "text": text, "recipient": user.uid]
ref.updateChildValues(values)
inputBar.inputTextView.text = ""
}
}
答案 2 :(得分:0)
好吧,我也在视图控制器类中添加了它
import MessageInputBar