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