4

I want to send message using xmpp to openFire everything works perfect even i can receive message. but not able to send i don't know why? i tried this code:

@IBAction func SendMessageClicked(_ sender: AnyObject) {

       let message = messageTextField.text
        var clientJid: XMPPJID!
        clientJid = XMPPJID.init(string: "Bure@ip-772-99-99-99.ec3.internal")
        let senderJID = clientJid
          let msg = XMPPMessage(type: "chat", to: senderJID)
        msg?.addBody(message)
        stream?.send(msg)
}

As it doesnot throw any error but message does not send. Plese help.

Mad Burea
  • 531
  • 8
  • 22

2 Answers2

0
 let xMessage = XMPPMessage(type: "chat", to: XMPPJID(string: clientJid))
        xMessage.addBody(message)
        xMessage.addOriginId(stream.generateUUID)
        stream.send(xMessage)
Suresh Mopidevi
  • 919
  • 3
  • 9
  • 24
0

I had the same problem and I just found the issue. Make sure the connection is established and authentication is done completely before trying to send messages. To do that you can use these XMPPStreamDelegate functions:

func xmppStreamDidConnect(_ stream: XMPPStream!) {
    //Connection is now established
}

func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
    //Athentication is done. Now you can send messages.
}
HemOdd
  • 697
  • 1
  • 7
  • 23