For iOS and XMPP, add friends and friends for Request Processing

Source: Internet
Author: User
Xmppstream * xmppstream; xmppreconnect * xmppreconnect; xmpproster * xmpproster; // user object // object to be added
// Add friend # pragma mark and friend-(void) secret :( 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];}

// Process and add friends # pragma mark process and add a friend callback, add a friend-(void) xmpproster :( xmpproster *) sender didreceivepresencesubscriptionrequest :( xmpppresence *) presence {// obtain 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]; [xmpproster acceptpresencesubscriptionrequestfrom: jid andaddtoroster: Yes];}
// Add a friend to the next processing # pragma mark receives the friend's online/offline status-(void) xmppstream :( xmppstream *) sender didreceivepresence :( xmpppresence *) presence {// ddlogverbose (@ "% @: % @ ^ % @", this_file, this_method, [presence fromstr]); // obtain the friend status nsstring * presencetype = [nsstring stringwithformat: @ "% @", [presence type]; // online/offline // current user // nsstring * userid = [nsstring stringwithformat: @ "% @", [[Sender myjid] user]; // online user nsstring * presencefromuser = [nsstring stringwithformat: @ "% @", [[presence from] user]; nslog (@ "presencetype: % @", presencetype ); nslog (@ "User: % @", presencefromuser); // Add a friend if ([presencetype is#tostring: @ "subscribed"]) {xmppjid * jid = [xmppjid jidwithstring: [nsstring stringwithformat: @ "% @", [presence from]; [xmpproster acceptpresencesubscriptionrequestfrom: jid andaddtoroster: Yes];}

# Pragma MARK: delete a friend, cancel adding a friend, or delete-(void) removebuddy :( nsstring *) name {xmppjid * jid = [xmppjid jidwithstring: [nsstring stringwithformat: @ "% @", name, xmpphost]; [self xmpproster] removeuser: jid];}

Note the Host Name and processing sequence

Related Article

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.