Transferred from: http://www.cnblogs.com/dyingbleed/archive/2013/05/16/3075105.html
Send and receive messages
Receiving messages
By implementing
-(void) Xmppstream: (xmppstream *) sender Didreceivemessage: (xmppmessage *) message;
Method
When the content of the <message/> Tag is received, the Xmppframework framework callbacks the method
Depending on the XMPP protocol, the contents of the message body are stored in the label <body/>
-(void) Xmppstream: (Xmppstream *) sender Didreceivemessage: (xmppmessage *) message { NSString *messagebody = [[ Message elementforname:@ "Body"] stringvalue];}
Send Message
To send a message, we need to place the data in the <message/> Tag, based on the XMPP protocol, for example:
<message type= "Chat" to= "[email protected]" >
<body>hello world!<body/>
<message/>
-(void) SendMessage: (NSString *) message Touser: (NSString *) User { nsxmlelement *body = [Nsxmlelement Elementwithnam e:@ "Body"]; [Body setstringvalue:message]; Nsxmlelement *message = [nsxmlelement elementwithname:@ "message"]; [Message addattributewithname:@ "type" stringvalue:@ "chat"]; NSString *to = [NSString stringwithformat:@ "%@ @example. com", user]; [Message addattributewithname:@ "to" stringvalue:to]; [Message addchild:body]; [Self.xmppstream sendelement:message];}
IOS XMPP uses Xmppframewok (quad): Send and receive messages