"IOS XMPP" using Xmppframewok (v): Friends List

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.