0

I am trying to use MessageKit inside my application, and I have the view loading and showing messages.

However, the "Send" button never triggers the messageInputBar delegate and I am unsure why. There is not much to hook up, if I downgrade to version 1.0.0, it works and triggers when you press Send, upgrade to the newest version and it breaks.

import UIKit
import MessageKit
import InputBarAccessoryView

private var messages: [Message] = []

class InboxThreadViewController: MessagesViewController, MessageInputBarDelegate {

    @objc public var myValue:String?
    private var messages: [Message] = []
    override func viewDidLoad() {
        super.viewDidLoad()


        messageInputBar.delegate = self
        messagesCollectionView.messagesDataSource = self
        messagesCollectionView.messagesLayoutDelegate = self
        messagesCollectionView.messagesDisplayDelegate = self
        title = "MessageKit"

func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {
        print("Message : \(text)")
        NSLog("HELLO")
    } 
    }
Anthony Taylor
  • 3,073
  • 3
  • 21
  • 30

2 Answers2

1

To resolve this problem you have to extend instead of MessageInputBarDelegate the InputBarAccessoryViewDelegate protocol. To make your code more elegant, proceed this way :

class InboxThreadViewController: MessagesViewController { .. }

extension InboxThreadViewController: InputBarAccessoryViewDelegate {
  func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
    //Handle message input text here
  }
}
KevinMo
  • 2,740
  • 2
  • 8
  • 14
1

my MessageKit (3.0.0) is working,

before:

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

after:

func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String)
smapira
  • 87
  • 7