Transferred from: http://www.cnblogs.com/dyingbleed/archive/2013/05/17/3082226.html
Friends List
Buddy List, called roster in XMPP, roster?
Get roster requires client to send <iq/> label to XMPP server-side query
An IQ request:
<iq type= "Get"
from= "[Email protected]"
to= "example.com"
Id= "1234567" >
<query xmlns= "Jabber:iq:roster"/>
<iq/>
The Type property, which describes the IQ as a get, is similar to HTTP, requesting information from the server side
From property, message source, here is your JID
To attribute, message destination, here is the server domain name
ID attribute, which marks the request ID, when the server finishes processing a request for a get type of IQ, the response result type IQ ID is the same as the ID of the request IQ
<query xmlns= "Jabber:iq:roster"/> sub-tab, stating that the client needs to query roster
-(void) Queryroster { nsxmlelement *query = [nsxmlelement elementwithname:@ "Query" xmlns:@ "Jabber:iq:roster"]; Nsxmlelement *iq = [nsxmlelement elementwithname:@ "IQ"]; Xmppjid *myjid = Self.xmppStream.myJID; [IQ addattributewithname:@ "from" stringValue:myJID.description]; [IQ addattributewithname:@ "to" stringValue:myJID.domain]; [IQ addattributewithname:@ "id" stringvalue:[self Generateid]]; [IQ addattributewithname:@ "type" stringvalue:@ "get"]; [IQ addchild:query]; [Self.xmppstream Sendelement:iq];}
An IQ response:
<iq type= "Result"
Id= "1234567"
to= "[Email protected]" >
<query xmlns= "Jabber:iq:roster" >
<item jid= "[email protected]" name= "Xiao Yan"/>
<item jid= "[email protected]" name= "Xiao Qiang"/>
<query/>
<iq/>
The type attribute, which describes the result of the IQ, is the results of the query
<query xmlns= "Jabber:iq:roster"/> Label Sub-label <item/>, for the child of the query, that is, roster
The item tag's properties, including the friend's JID, and other optional attributes, such as nicknames.
By implementing
-(BOOL) Xmppstream: (xmppstream *) sender Didreceiveiq: (Xmppiq *) IQ;
Method
When the content of the <iq/> Tag is received, the Xmppframework framework callbacks the method
-(BOOL) Xmppstream: (Xmppstream *) sender Didreceiveiq: (XMPPIQ *) IQ { if ([@ "result" isEqualToString:iq.type]) { nsxmlelement *query = iq.childelement; if ([@ "Query" IsEqualToString:query.name]) { Nsarray *items = [query children]; For (nsxmlelement *item in items) { NSString *jid = [item attributestringvalueforname:@ "Jid"]; Xmppjid *xmppjid = [Xmppjid Jidwithstring:jid]; [Self.roster Addobject:xmppjid];}}}
"IOS XMPP" using Xmppframewok (v): Friends List