MessageKit / MessageInputBar

A powerful InputAccessoryView ideal for messaging applications
MIT License
64 stars 44 forks source link

messageInputBar.delegate = self does not work #33

Open taigaisatiger opened 3 years ago

taigaisatiger commented 3 years ago

I am trying to trying to implement a chat feature in my app but it is not going so well. I was trying to check if the send button was working correctly by printing out "button is pushed", but it didn't get printed. I realized messageInputBar.delegate = self was not in the code and I thought that was the problem and as I put in the line of code an error below popped up. I don't know how to fix this and it would be a great help if you could give me an advice on what I should do. Cannot assign value of type 'MessageKitChatViewController' to type 'InputBarAccessoryViewDelegate?' Add missing conformance to 'InputBarAccessoryViewDelegate' to class 'MessageKitChatViewController'

`import UIKit import MessageKit import MessageInputBar import FirebaseFirestore import FirebaseAuth import FirebaseStorage import Nuke

struct Sender: SenderType{ var senderId: String var displayName: String }

struct MessageKitMessage: MessageType{ var sender: SenderType var messageId: String var sentDate: Date var kind: MessageKind }

class MessageKitChatViewController: MessagesViewController, MessagesDataSource, MessagesLayoutDelegate, MessagesDisplayDelegate, MessageInputBarDelegate{

var senderUser = Auth.auth().currentUser!
var messages = [MessageType]()

let currentUser = Sender(senderId: Auth.auth().currentUser!.uid , displayName: Auth.auth().currentUser!.displayName ??  "Name not found")

override func viewDidLoad() {
    super.viewDidLoad()
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messageInputBar.delegate = self
}

func currentSender() -> SenderType {
    return currentUser
}

func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
    return messages[indexPath.section]
}

func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
    return messages.count
}

func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {

// let message = MessageKitMessage(sender: currentUser, messageId: UUID().uuidString, sentDate: Timestamp().dateValue(), kind: .text(text)) print("button is pushed") }

}

`