(轉(zhuǎn)載) XMPPFrameWork IOS 開發(fā)(五)獲取好友信息和添加刪除好友

原始地址: XMPPFrameWork iOS 開發(fā)(五)獲取好友信息和添加刪除好友

好友列表和好友名片
[cpp] view plain copy print?
[_xmppRoster fetchRoster];//獲取好友列表  
  
//獲取到一個好友節(jié)點  
- (void)xmppRoster:(XMPPRoster *)sender didRecieveRosterItem:(NSXMLElement *)item  
  
//獲取完好友列表  
- (void)xmppRosterDidEndPopulating:(XMPPRoster *)sender  
  
//到服務(wù)器上請求聯(lián)系人名片信息  
- (void)fetchvCardTempForJID:(XMPPJID *)jid;  
  
//請求聯(lián)系人的名片,如果數(shù)據(jù)庫有就不請求,沒有就發(fā)送名片請求  
- (void)fetchvCardTempForJID:(XMPPJID *)jid ignoreStorage:(BOOL)ignoreStorage;  
  
//獲取聯(lián)系人的名片,如果數(shù)據(jù)庫有就返回,沒有返回空,并到服務(wù)器上抓取  
- (XMPPvCardTemp *)vCardTempForJID:(XMPPJID *)jid shouldFetch:(BOOL)shouldFetch;  
  
//更新自己的名片信息  
- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp;  
  
//獲取到一盒聯(lián)系人的名片信息的回調(diào)  
- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule   
        didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp   
                     forJID:(XMPPJID *)jid  

添加好友
[cpp] view plain copy print?
//name為用戶賬號  
- (void)XMPPAddFriendSubscribe:(NSString *)name    
{    
  //XMPPHOST 就是服務(wù)器名,  主機名      
    XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];    
    //[presence addAttributeWithName:@"subscription" stringValue:@"好友"];    
    [xmppRoster subscribePresenceToUser:jid];    
        
}  

[cpp] view plain copy print?
//收到添加好友的請求  
- (void)xmppRoster:(XMPPRoster *)sender didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence    
{    
    //取得好友狀態(tài)    
    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];    
    
}    


刪除好友
[cpp] view plain copy print?
//刪除好友,name為好友賬號  
- (void)removeBuddy:(NSString *)name    
{    
    XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];    
        
    [self xmppRoster] removeUser:jid];    
}  
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容