首页 > 代码库 > xmpp获取好友信息和添加删除好友(4)
xmpp获取好友信息和添加删除好友(4)
原始地址: XMPPFrameWork IOS 开发(五)获取好友信息和添加删除好友
好友列表和好友名片
[cpp] view plaincopyprint?
- [_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
添加好友
[cpp] view plaincopyprint?
- //name为用户账号
- - (void)XMPPAddFriendSubscribe:(NSString *)name
- {
- //XMPPHOST 就是服务器名, 主机名
- XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];
- //[presence addAttributeWithName:@"subscription" stringValue:@"好友"];
- [xmppRoster subscribePresenceToUser:jid];
- }
[cpp] view plaincopyprint?
- //收到添加好友的请求
- - (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];
- }
删除好友
[cpp] view plaincopyprint?
- //删除好友,name为好友账号
- - (void)removeBuddy:(NSString *)name
- {
- XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];
- [self xmppRoster] removeUser:jid];
- }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。