关闭

XMPP学习记录六:聊天室

2949人阅读 评论(0) 收藏 举报
分类:

聊天室

  1. //初始化聊天室  
  2. XMPPJID *roomJID = [XMPPJID jidWithString:ROOM_JID];    
  3.     
  4. xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self jid:roomJID];    
  5.     
  6. [xmppRoom activate:xmppStream];    
  7. [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];  

  1. //创建聊天室成功  
  2. - (void)xmppRoomDidCreate:(XMPPRoom *)sender  
  3. {  
  4.     DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);  
  5. }  



  1. //加入聊天室,使用昵称  
  2. [xmppRoom joinRoomUsingNickname:@"quack" history:nil];   

  1. //获取聊天室信息  
  2. - (void)xmppRoomDidJoin:(XMPPRoom *)sender  
  3. {  
  4.     [xmppRoom fetchConfigurationForm];  
  5.     [xmppRoom fetchBanList];  
  6.     [xmppRoom fetchMembersList];  
  7.     [xmppRoom fetchModeratorsList];  
  8. }  


如果房间存在,会调用委托
  1. // 收到禁止名单列表    
  2. - (void)xmppRoom:(XMPPRoom *)sender didFetchBanList:(NSArray *)items;    
  3. // 收到好友名单列表    
  4. - (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items;    
  5. // 收到主持人名单列表    
  6. - (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items;   


房间不存在,调用委托

  1. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchBanList:(XMPPIQ *)iqError;    
  2. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError;    
  3. - (void)xmppRoom:(XMPPRoom *)sender didNotFetchModeratorsList:(XMPPIQ *)iqError;  

离开房间

  1. [xmppRoom deactivate:xmppStream];    

  1. //离开聊天室  
  2. - (void)xmppRoomDidLeave:(XMPPRoom *)sender  
  3. {  
  4.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
  5. }  


其他代理

  1. //新人加入群聊  
  2. - (void)xmppRoom:(XMPPRoom *)sender occupantDidJoin:(XMPPJID *)occupantJID  
  3. {  
  4.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
  5. }  
  6. //有人退出群聊  
  7. - (void)xmppRoom:(XMPPRoom *)sender occupantDidLeave:(XMPPJID *)occupantJID  
  8. {  
  9.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
  10. }  
  11. //有人在群里发言  
  12. - (void)xmppRoom:(XMPPRoom *)sender didReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID  
  13. {  
  14.     DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);  
  15. }  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:208830次
    • 积分:3793
    • 等级:
    • 排名:第8427名
    • 原创:171篇
    • 转载:14篇
    • 译文:1篇
    • 评论:33条
    文章分类
    最新评论