原始地址: XMPPFrameWork IOS 開發(五)擷取好友資訊和添加移除朋友
好友名單和好友名片
[_xmppRoster fetchRoster];//擷取好友名單//擷取到一個好友節點- (void)xmppRoster:(XMPPRoster *)sender didRecieveRosterItem:(NSXMLElement *)item//擷取完好友名單- (void)xmppRosterDidEndPopulating:(XMPPRoster *)sender//到伺服器上請求連絡人名片資訊- (void)fetchvCardTempForJID:(XMPPJID *)jid;//請求連絡人的名片,如果資料庫有就不請求,沒有就發送名片請求- (void)fetchvCardTempForJID:(XMPPJID *)jid ignoreStorage:(BOOL)ignoreStorage;//擷取連絡人的名片,如果資料庫有就返回,沒有返回空,併到伺服器上抓取- (XMPPvCardTemp *)vCardTempForJID:(XMPPJID *)jid shouldFetch:(BOOL)shouldFetch;//更新自己的名片資訊- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp;//擷取到一盒連絡人的名片資訊的回調- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid
添加好友
//name為使用者帳號- (void)XMPPAddFriendSubscribe:(NSString *)name { //XMPPHOST 就是伺服器名, 主機名稱 XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]]; //[presence addAttributeWithName:@"subscription" stringValue:@"好友"]; [xmppRoster subscribePresenceToUser:jid]; }
//收到添加好友的請求- (void)xmppRoster:(XMPPRoster *)sender didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence { //取得好友狀態 NSString *presenceType = [NSString stringWithFormat:@"%@", [presence type]]; //online/offline //請求的使用者 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]; }
移除朋友
//移除朋友,name為好友帳號- (void)removeBuddy:(NSString *)name { XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]]; [self xmppRoster] removeUser:jid]; }