Friends List
Buddy list, known as the XMPP roster, the roster?
Obtain client roster need to send <iq /> tag to the XMPP server query
A request IQ:
<iq type="get"
from="[email protected]"
to="example.com"
id="1234567">
<query xmlns="jabber:iq:roster"/>
<iq />
type attribute describes the type of the iq get, similar to HTTP, request information to the server
from the properties, sources, here's your JID
to property, the message destination, here is the domain name server
id attribute, the tag ID request, when the server requests get processed iq type, the same result iq type response with the request ID of ID iq
<Query xmlns = "jabber: iq: roster" /> sub-tab shows 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]; }
A response IQ:
<iq type="result"
id="1234567"
to="[email protected]">
<query xmlns="jabber:iq:roster">
<item jid="[email protected]" name="小燕" />
<item jid="[email protected]" name="小强"/>
<query />
<iq />
type attribute, that the results of the iq type of result, query
Child tag <query xmlns = "jabber:: iq roster" /> tag in the <item />, as the child of inquiry, namely roster
Property item tag, comprising the JID friends, and other optional attributes, such as a nickname and the like.
By implementing
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq;
method
When receiving the content <iq /> tag, XMPPFramework frame callback 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]; } } } }
Reproduced in: https: //www.cnblogs.com/dyingbleed/archive/2013/05/17/3082226.html