// 实现好友状态的获取 - 在线、离线 别的状态自己去写一下判断和回掉就好
.h
1 /*! 2 * @Author Dylan. 3 * 4 * Paresence 5 */ 6 typedef void (^userGoOnline) (NSString *); 7 typedef void (^userGoOffline) (NSString *); 8 9 - (void)refreshRosterPresence: (userGoOnline)online 10 offline: (userGoOffline)offline;
.m
1 #pragma mark presence 2 - (void)refreshRosterPresence: (userGoOnline)online 3 offline: (userGoOffline)offline { 4 5 self.rosterOnline = online; 6 self.rosterOffline = offline; 7 [self online]; 8 } 9 10 - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence { 11 12 // get presence type 13 NSString * presenceType = [presence type]; 14 NSString * userID = [[sender myJID] user]; 15 16 NSString * presencrFromUser = [[presence from] user]; 17 if (![presencrFromUser isEqualToString:userID]) { 18 if ([presenceType isEqualToString:@"available"]) { 19 self.rosterOnline(userID); 20 } else if ([presenceType isEqualToString:@"unavailable"]) { 21 self.rosterOffline(userID); 22 } 23 } 24 }
注意这里的第7行代码。
把我们以前写的self online这句话 从以前的登录成功就去获取好友状态改到我们的刷新好友状态里边。
补上Block回掉申明
1 /*! 2 * call back block 3 */ 4 @property (nonatomic, copy) userGoOnline rosterOnline; 5 @property (nonatomic, copy) userGoOffline rosterOffline;