// 实现好友状态的获取 - 在线、离线 别的状态自己去写一下判断和回掉就好
.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 } 8 9 - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence { 10 11 // get presence type 12 NSString * presenceType = [presence type]; 13 NSString * userID = [[sender myJID] user]; 14 15 NSString * presencrFromUser = [[presence from] user]; 16 if (![presencrFromUser isEqualToString:userID]) { 17 if ([presenceType isEqualToString:@"available"]) { 18 self.rosterOnline(presencrFromUser); 19 } else if ([presenceType isEqualToString:@"unavailable"]) { 20 self.rosterOffline(presencrFromUser); 21 } 22 } 23 }
补上Block回掉申明
1 /*! 2 * call back block 3 */ 4 @property (nonatomic, copy) userGoOnline rosterOnline; 5 @property (nonatomic, copy) userGoOffline rosterOffline;