你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> xmpp好友狀態4

xmpp好友狀態4

編輯:IOS技巧綜合
[摘要]本文是對xmpp好友狀態4的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

// 實現好友狀態的獲取 - 在線、離線 別的狀態自己去寫一下判斷和回掉就好

.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;
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved