// 實現好友狀態的獲取 - 在線、離線 別的狀態自己去寫一下判斷和回掉就好
.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;