Original address: xmppframework iOS development (5) Getting friend information and adding and deleting friends
Friend list and friend business card
[_ Xmpproster fetchroster]; // obtain a friend list // obtain a friend node-(void) xmpproster :( xmpproster *) sender didrecieverosteritem :( nsxmlelement *) item // obtain the friends list-(void) xmpprosterdidendpopulating :( xmpproster *) sender // request the contact name card information on the server-(void) fetchvcardtempforjid :( xmppjid *) jid; // request the contact's business card. If the database does not, send the business card Request-(void) fetchvcardtempforjid :( xmppjid *) jid ignorestorage :( bool) ignorestorage; // obtain the contact's business card. If the database has one, no blank is returned, and the system crawls-(xmppvcardtemp *) vcardtempforjid :( xmppjid *) jid shouldfetch :( bool) shouldfetch; // update your business card information-(void) updatemyvcardtemp :( xmppvcardtemp *) vcardtemp; // call back (void) xmppvcardtempmodule (xmppvcardtempmodule *) vcardtempmodule didreceivevcardtemp :( xmppvcardtemp *) vcardtemp forjid :( xmppjid *) jid
Add friends
// Name is the user account-(void) xmppaddfriendsubscribe :( nsstring *) name {// xmpphost is the server name, host name xmppjid * jid = [xmppjid jidwithstring: [nsstring stringwithformat: @ "% @", name, xmpphost]; // [presence addattributewithname: @ "subscribe" stringvalue: @ "friend"]; [xmpproster subscribepresencetouser: jid];}
// Receive a friend adding request-(void) xmpproster :( xmpproster *) sender didreceivepresencesubscriptionrequest :( xmpppresence *) Presence {// obtain the friend status nsstring * presencetype = [nsstring stringwithformat: @ "% @", [presence type]; // online/offline // The requested user nsstring * presencefromuser = [nsstring stringwithformat: @ "% @", [[presence from] user]; nslog (@ "presencetype: % @", presencetype); nslog (@ "presence2: % @ sender2: % @", presence, sender); xmppjid * jid = [xmppjid jidwithstring: presencefromuser]; // receives a friend adding request [xmpproster acceptpresencesubscriptionrequestfrom: jid andaddtoroster: Yes];}
Delete friends
// Delete a friend. The name is a friend account-(void) removebuddy :( nsstring *) name {xmppjid * jid = [xmppjid jidwithstring: [nsstring stringwithformat: @ "% @", name, xmpphost]; [self xmpproster] removeuser: jid];}