Friends List
Buddy List, called rosterin 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
the ID attribute, which marks the request ID, when the server finishes processing the request get type IQ , the response of the result type IQ of the 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/>, as a 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 ofthe <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];
}
}
}
}