5

我刚刚将我的代码更新为 swift 4.2 并修复了所有错误。现在我正在尝试使用“MessageKit”将信使放入我的应用程序中。一切都更新了,但我遇到了这些问题......现在它说的是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 = ""
}

}

参数标签 '(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())
    }
4

3 回答 3

7

你安装了 MessageInputBar吗?你可以这样安装

pod 'MessageInputBar'

由于MessageKit 2.0.0你必须安装MessageInputBar

于 2018-11-19T16:29:04.067 回答
3

那时添加也对我有用

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 = ""
    }
}
于 2019-09-02T23:33:04.923 回答
0

好吧,我还在视图控制器类中添加了这个

import MessageInputBar

于 2019-05-03T10:42:25.937 回答