Swift MessageKit 问题 - 运行 swift 4.2
Swift MessageKit problems - running swift 4.2
我刚刚将我的代码更新到 swift 4.2 并修复了所有错误。现在我正在尝试使用 'MessageKit' 将信使放入我的应用程序。一切都已更新,但我遇到了这些问题...现在它说 MessagesInputBarDelegate
"Use of undeclared type 'MessagesInputBarDelegate'"
和
"Use of undeclared type 'MessageInputBar'"
此外,
"Argument Labels '(type:)' do not match any available overloads"
和
"Cannot convert value of type'_?' to expected argument 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 = ""
}
}
参数标签“(type:)”不匹配任何可用的重载
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())
}
你安装了MessageInputBar了吗?你可以这样安装它
pod 'MessageInputBar'
因为 MessageKit 2.0.0 你必须安装 MessageInputBar
我也在视图控制器中添加了这个class
import MessageInputBar
添加对我也有用
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 = ""
}
}
我刚刚将我的代码更新到 swift 4.2 并修复了所有错误。现在我正在尝试使用 'MessageKit' 将信使放入我的应用程序。一切都已更新,但我遇到了这些问题...现在它说 MessagesInputBarDelegate
"Use of undeclared type 'MessagesInputBarDelegate'"
和
"Use of undeclared type 'MessageInputBar'"
此外,
"Argument Labels '(type:)' do not match any available overloads"
和
"Cannot convert value of type'_?' to expected argument 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 = ""
}
}
参数标签“(type:)”不匹配任何可用的重载
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())
}
你安装了MessageInputBar了吗?你可以这样安装它
pod 'MessageInputBar'
因为 MessageKit 2.0.0 你必须安装 MessageInputBar
我也在视图控制器中添加了这个class
import MessageInputBar
添加对我也有用
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 = ""
}
}