4

I am using QuickBlox iOS SDK (version 2.9.2) and got a failure with error code 422 when calling

[QBRequest createObject:qbcoCustomObject successBlock:^(QBResponse *response, QBCOCustomObject *object) {
} errorBlock:^(QBResponse *response) {
}];

It happens OCCASIONALLY and does not resume until I logout and login QuickBlox again.

The error message is as follows:

2017-04-24 06:18:45.855557 App[8720:4958563] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: client error (422)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17422ed40> { URL: https://api.quickblox.com/data/MyCircleComments.json } { status code: 422, headers {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 45;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Mon, 24 Apr 2017 12:18:45 GMT";
    "QB-Token-ExpirationDate" = "2017-04-24 14:09:35 +0000";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "openresty/1.9.15.1";
    Status = "422 Unprocessable Entity";
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 89f509abd6fd7f61d02e34ae9e83ce70;
    "X-Runtime" = "0.009477";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
} }, NSErrorFailingURLKey=https://api.quickblox.com/data/MyCircleComments.json, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a7b22 62617365 223a5b22 466f7262 69646465 6e2e204e 65656420 75736572 2e225d7d 7d>, NSLocalizedDescription=Request failed: client error (422)}
2017-04-24 06:18:45.856659 App[8720:4958563] [QBCore] Response error reasons: {
    errors =     {
        base =         (
            "Forbidden. Need user."
        );
    };
}

Due to the fact that it resumes only after I logout and login again, I was thinking that it may be related to session expiry. I added login method at the app's didFinishLaunching and didBecomeActive so that the app will automatically re-login to make sure the login session be valid. The login method I use is

[QBRequest logInWithUserLogin:sUsername password:sPassword successBlock:^(QBResponse *response, QBUUser *user) {
    } errorBlock:^(QBResponse *response) {
    }];

and by setting breakpoints I am sure each time the auto relogin did succeed.

However, app's auto-relogin does not work. The failure still happens occasionally and the only way out is logout and login manually.

I googled this issue and found a bunch of topic but none seems to meet my problem. (One post suggests that the time of device may not be synchronized but actually my iPhone is using the network time.)

Can anyone give me a hint why it fails and a solution is highly appreciated. Thanks in advance.

kuang
  • 309
  • 1
  • 11
  • Please create an issue in [our repo](https://github.com/QuickBlox/quickblox-ios-sdk) and add full logs. – VitGur Apr 27 '17 at 09:53
  • With further investigation, I find this is not session expiry, but Quickblox's performance issue. My app will retrieve request all the users' information and then download all the avatar (from Contents) at startup, which is a relatively heavy duty. If I post something ([QBRequest createObject...]) immediately after the app started, the 422 error will surely occur, but if I wait 5 seconds or so for the startup duty to complete before posting, then this issue will never occur. My solution then is to do the startup loading synchronously and it is working well now. – kuang Apr 28 '17 at 21:24

2 Answers2

2

One of the best answer for above issue:-

**"Bad timestamp means that you send invalid timestamp value on session creation, which is based on your phone time. Your device time shouldn't differ from server more than 2 hours. We suggest you synchronize time on your devices with NTP service or just set tick 2 checkboxes in Settings in your device: Automatic date & time and Automatic time zone.

Hope this help"**

Ref :- https://github.com/QuickBlox/quickblox-ios-sdk/issues/452

From setting of the device set timezone automatic on.

Hope this will help you.

Er.Shreyansh Shah
  • 1,482
  • 1
  • 9
  • 29
0

Try to get Quickblox session token

[[[QBSession currentSession] sessionDetails] token];

And check session type via REST API

//QuickBlox Documentation 
curl -X GET \
-H "QuickBlox-REST-API-Version: 0.1.0" \
-H "QB-Token: 8b75a6c7191285499d890a81df4ee7fe49bc732a" \
https://api.quickblox.com/session.json

If field "user_id" of your token will be equal to 0 this mean that you have "application-token" type, and you cannot create or update items on QBlox, after login with session token "upgrades" to "user-token"

I have similar issue, and i made extra check, if token-type is application, then you need login with same user again (recursively call login method if you can), i know that its a workaround, but we cant dig deeper because all locked in Quickblox.framework

Mr.Fingers
  • 1,105
  • 1
  • 11
  • 15
  • It turned to be like a congestion because when I shaped the massive loading the issue was gone. Really appreciate your advice! – kuang Jul 19 '17 at 01:37