zoukankan      html  css  js  c++  java
  • xmpp好友状态4

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

    .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;
  • 相关阅读:
    Linux I2C驱动程序设计
    I2C裸机驱动程序设计
    Linux串口驱动程序设计
    Linux平台总线设备驱动
    Linux总线设备驱动模型
    Linux内核同步机制
    Linux设备驱动开发基础--阻塞型设备驱动
    模型评估方法和性能指标
    机器学习——XGBoost
    机器学习——GBDT
  • 原文地址:https://www.cnblogs.com/Dylan-Alice/p/Dylan_XMPP4.html
Copyright © 2011-2022 走看看