nik
nik

Reputation: 2329

XMPP - Enabling Chat Among Users

I implemented an iPhone chat application using XMPP protocol and Openfire server. I can list the users in XMPP Client but I don't know how to enable chat among those users.

I would like to know:

  1. How to send text to selected user

  2. How to promote a chat window and initiate text chat between those two users

Thanks.

Upvotes: 0

Views: 995

Answers (1)

Marc
Marc

Reputation: 586

The XMPPFramework is just that, a framework. You must construct a full UI and all the other logic necessary to create a chat application.

To send a chat message to another user, you would use code similar to this:

NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:@"Message text here"];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:@"recipient.jid.com"];
[message addChild:body];

[xmppStream sendElement:message];

You would need to create the UI using a UITextField to enter the message text for instance. XMPPFramework is the low-level code to send and receive XMPP stanzas. You would also need to add code to where XMPP Messages are received, probably use the isChatMessage method and then notify the recipient that they've received a message, display it to them and allow them to reply.

Upvotes: 2

Related Questions