5

I had just updated my code to swift 4.2 and fixed all the errors. Now I am trying to use 'MessageKit' to put a messenger into my app. Everything is updated yet I am having these problems... now it is saying for MessagesInputBarDelegate

"Use of undeclared type 'MessagesInputBarDelegate'"

and

"Use of undeclared type 'MessageInputBar'"

Also,

"Argument Labels '(type:)' do not match any available overloads"

and

"Cannot convert value of type'_?' to expected argument type 'URL?"

Use of undeclared type 'MessagesInputBarDelegate'

Use of undeclared type 'MessageInputBar'

extension CustomerChatViewController: MessagesInputBarDelegate {

func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {
    let message = Message(user: user, content: text)

    save(message)
    inputBar.inputTextView.text = ""
}

}

Argument labels '(type:)' do not match any available overloads

let cameraItem = UIBarButtonItem(type: .system)

Cannot convert value of type '_?' to expected argument type 'URL?'

let imageName = [UUID().uuidString, String(Date().timeIntervalSince1970)].joined()
    storage.child(channelID).child(imageName).putData(data, metadata: metadata) { meta, error in
        completion(meta?.downloadURL())
    }
Julien Kode
  • 5,010
  • 21
  • 36
Lukas Bimba
  • 817
  • 14
  • 35

3 Answers3

7

Have you install MessageInputBar ? You can install it like that

pod 'MessageInputBar'

Since MessageKit 2.0.0 you have to install MessageInputBar

Julien Kode
  • 5,010
  • 21
  • 36
  • 3
    If the `MessageInputBar` pod is required to use the `MessageKit` pod, it seems like the podspec of `MessageKit` should be updated to reflect that dependency. Manually adding a dependency to your own `Podfile` seems like a workaround rather than a real solution. – Dávid Pásztor Nov 19 '18 at 16:46
  • 1
    @DávidPásztor you're right, I'll take a look at this more closely – Julien Kode Nov 19 '18 at 20:32
  • Hi there, I'm doing the review rounds and I see you want to remove the `MessageData` part from the question. Why, is it unrelated to the other errors in the question? Next time just comment to the author and ask them to remove it! – Maarten Bodewes Nov 20 '18 at 02:43
  • The error of message data cames because of a wrong import of another module. In addition there are another stack overflow post for that – Julien Kode Nov 20 '18 at 06:48
  • For Carthage users, include this in your Cartfile: `github "MessageKit/MessageInputBar"` – Dylan Jul 28 '20 at 21:04
3

adding worked for me too then

import InputBarAccessoryView

then in viewDidLoad() add this :

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)

    }

calling the delegate method :

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 = ""
    }
}
Di Nerd Apps
  • 770
  • 8
  • 15
0

Well i also added this in the view controller class

import MessageInputBar

stry-kai
  • 483
  • 4
  • 7