2016-10-06 60 views
2

我試過QuickBlox文檔方法,但最後一次請求的時間總是不變,實際上,當連接的用戶使用Quick blox進行任何活動(如與某人聊天)時應該更新。
但是,它保持不變(只給用戶登錄的時間)。

那麼它將如何更新每個請求?
我試過下面的代碼。QuickBlox iOS中的在線/離線問題

[QBACCESS fetchUserDetailsWithID:userID withCompeltionHandler:^(QBUUser *userDetails,BOOL status){ 
    if(status){ 
     QBUUser *user = userDetails; 
     NSInteger currentTimeInterval = [[NSDate date] timeIntervalSince1970]; 
     NSInteger userLastRequestAtTimeInterval = [[user lastRequestAt] timeIntervalSince1970]; 
     // if user didn't do anything last 1 minute (60 seconds) 
     if((currentTimeInterval - userLastRequestAtTimeInterval) > 60){ 
     //means user is offline 
     } 
     else{ 
     //user is online 
     } 
    } 
}]; 

在所有情況下,它顯示爲脫機狀態,因爲我的[用戶lastRequestAt]在用戶登錄時始終保持不變。
所以,它不是實時在線/離線。請幫助我

回答

1

經過大量研究,我發現只有通過訂閱狀態,我們才能實現使用QuickBlox實時在線/離線。

有四種訂閱狀態。

  1. QBPresenseSubscriptionStateNone
  2. QBPresenseSubscriptionStateTo
  3. QBPresenseSubscriptionStateFrom
  4. QBPresenseSubscriptionStateBoth

對於在線檢測的實時/ offile我們需要發送請求給對手(其他)的用戶,如果對方用戶接受他們的請求的裝置QBPresenseSubscriptionStateBoth,那麼雙方將知道對方,並且下面的委託方法將被調用,

- (void)chatContactListDidChange:(QBContactList *)contactList{ 

} 

- (void)chatDidReceiveContactItemActivity:(NSUInteger)userID 
           isOnline:(BOOL)isOnline 
            status:(NSString *)status{ 

    //here we check offline/online of particular user using ID. 
} 

欲瞭解更多詳情請通過:Contact List