1

I want to send my message and I know that it sends via

override func didPressSendButton(button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: NSDate!) {
    let message = JSQMessage(senderId: "alizade@my.co", senderDisplayName: "The Flash", date: NSDate(), text: text)

// SENDING CODE HERE
}

this function, but I do not know how to send it on press on the send button.

I searched and found this example:

OneMessage.sendMessage(text, to: recipient.jidStr, completionHandler: { (stream, message) -> Void in
    JSQSystemSoundPlayer.jsq_playMessageSentSound()
        self.finishSendingMessageAnimated(true)
    })

but I do not have .sendMessage method in my case. Any suggestions?

Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79

2 Answers2

0

sendMessage is just a function that was written outside of the the framework itself and I'm guessing is found in a subclass of JSQMessagesViewController. You'll still want to fire off whatever logic you'll run inside of didPressSendButton.

Tyten
  • 333
  • 2
  • 7
0

If you're using an array for the datasource of JSQMessagesViewController, just add the message (of type JSQMessage) to the array and call self.finishSendingMessageAnimated(true) to trigger the refresh and animation.

If you're using core data, you'll need to store the message in your database and depend on NSFetchedResultsController to trigger the update in controllerDidChangeContent or the other callback methods.

Since you're using XMPPFramework, you might also want to compose the message xml element and send it using the XMPPStream.

Hope that helps!

mohonish
  • 1,396
  • 1
  • 9
  • 21