大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > IOS技巧 > xmpp好友状态4

xmpp好友状态4

关键词:状态好友xmpp  阅读(1085) 赞(15)

[摘要]本文是对xmpp好友状态4的讲解,对学习IOS苹果软件开发有所帮助,与大家分享。

// 实现好友状态的获取 - 在线、离线 别的状态自己去写一下判断和回掉就好

.h

 /*!
  *  @Author Dylan.
  *
  *  Paresence
  */
 typedef void (^userGoOnline) (NSString *);
 typedef void (^userGoOffline) (NSString *);
 
 - (void)refreshRosterPresence: (userGoOnline)online
                       offline: (userGoOffline)offline;

.m

 #pragma mark presence
 - (void)refreshRosterPresence: (userGoOnline)online
                       offline: (userGoOffline)offline {
     
     self.rosterOnline = online;
     self.rosterOffline = offline;
 }
 
 - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {
     
     // get presence type
     NSString * presenceType = [presence type];
     NSString * userID = [[sender myJID] user];
     
     NSString * presencrFromUser = [[presence from] user];
     if (![presencrFromUser isEqualToString:userID]) {
         if ([presenceType isEqualToString:@"available"]) {
             self.rosterOnline(presencrFromUser);
         } else if ([presenceType isEqualToString:@"unavailable"]) {
             self.rosterOffline(presencrFromUser);
         }
     }
 }

补上Block回掉申明

 /*!
  *  call back block
  */
 @property (nonatomic, copy) userGoOnline rosterOnline;
 @property (nonatomic, copy) userGoOffline rosterOffline;


相关评论