// Obtain the status of friends-online or offline. Just write it for judgment and return.
. H
1 /*! 2 * @Author Dylan. 3 * 4 * Paresence 5 */ 6 typedef void (^userGoOnline) (NSString *); 7 typedef void (^userGoOffline) (NSString *); 8 9 - (void)refreshRosterPresence: (userGoOnline)online10 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 type12 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 }
Add block and Return Statement
1 /*!2 * call back block3 */4 @property (nonatomic, copy) userGoOnline rosterOnline;5 @property (nonatomic, copy) userGoOffline rosterOffline;
XMPP logon to register a friend group _ practical tutorial 4