Search code examples
ios7quickblox

lastRequestAt returning always 0.000000


When sending a message I'm checking if opponent user is online / offline, so I can send him APNS if he's offline:

NSTimeInterval currentTimeInterval = [[NSDate date] timeIntervalSince1970];
NSTimeInterval userLastRequestAtTimeInterval  = [[self.opponent lastRequestAt] timeIntervalSince1970];
if((currentTimeInterval - userLastRequestAtTimeInterval) > 300)
{
  //SEND APNS
}

or

NSTimeInterval currentTimeInterval = ([[NSDate date] timeIntervalSince1970]);
if(currentTimeInterval - [self.opponent.lastRequestAt timeIntervalSince1970] > 300)
{
    //SEND APNS
}

Opponent user lastRequestAt is always returning 0.000000 so it's always sending APNS, even when opponent is online.

I can get my user.lastRequestAt after login with username and password.

What I'm getting "null" is the "opponent user" last request when sending him a message: opponent.lastRequestAt.

self.opponent is not null, I have it's ID but not lastRequestAt property:

[QBUUser]:  
    ID:859106   
    created at:(null)   
    updated at:(null)           
    externalUserID:0            
    blobID:0            
    facebookID:(null)           
    twitterID:(null)            
    full name:(null)            
    email:(null)            
    login:(null)            
    phone:(null)            
    tags:(null)            
    lastRequestAt:(null)            
    website:(null)

I'm just sending message to opponent using it's ID as reference:

QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = self.opponent.ID;
[[QBChat instance] sendMessage:message];

What I can read in Output panel about getting opponent is:

GET https://api.quickblox.com/users/859106.xml

headers:{
    "QB-SDK" = "iOS 1.8.2";
    "Qb-Token" = 41243a780d6cb457e5fe88c4cf6e4827c6f88568;
    "QuickBlox-REST-API-Version" = "0.1.1";
}

Should be necessary to get opponent QBUser data other way before sending him a message?


Solution

  • Actually to send message you need only user ID. But if you want to use lastRequestAt field, you need to retrive QBUUser from Quickblox database. If you use [QBUUser user], you will create new user locally. Quickblox doesn't know this user yet.