3

I have a question regarding Quick blox API. Right now I am sign up an user using below code.

 [QBRequest createSessionWithSuccessBlock:^(QBResponse *response, QBASession *session) {
            // session created

            QBUUser *user = [QBUUser user];
            user.password = userPasswordTextField.text;
            user.login = userNameTextField.text;
            user.fullName = userRealNameTextField.text;
            user.email = userEmailTextField.text;

            // Registration sign up of User
            [QBRequest signUp:user successBlock:^(QBResponse *response, QBUUser *user) {

                [QBRequest createSessionWithSuccessBlock:^(QBResponse *response, QBASession *session) {
                    NSLog(@"checkingl registering");
                    [QBRequest userWithLogin:user.login successBlock:^(QBResponse *response, QBUUser *user) {
                        NSLog(@"checkingl updatingqb");

                    } errorBlock:^(QBResponse *response) {
                        // Handle error
                    }];

                }errorBlock:^(QBResponse *response) {
                    // Handle error
                }];

            } errorBlock:^(QBResponse *response) {
                // Handle error here
                NSLog(@"error while signing up with QB");

                NSLog(@"fail sign Up %@",response);;

                [self showAlert:nil message:@"User with login that has already been taken" cancelButtonTitle:nil otherButtonTitle:@"OK"];


                return ;

            }];
        } errorBlock:^(QBResponse *response) {
            // handle errors
            NSLog(@" error in creating session %@", response.error);
        }];

In above code first I am creating a session and sign up an new user, then I am login user. At sign up time I did't log in user for QuickBlox Chat at signup time, But later when I will log in into Quick blox chat in another module, still I have to create new session or I have to maintain new session.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
  • You'r asking what to when starting chat?? – Saad Dec 22 '14 at 07:23
  • http://stackoverflow.com/questions/27388204/forced-to-create-a-new-quickblox-session-every-time-ios-app-is-opened saad please check I have similar doubt. – Gajendra Rawat Dec 22 '14 at 07:26
  • Naeem answers seems perfect. Lemme know if it don't works I'll download my code from repo and will let you know How I managed this issue. It was some sort of same as Naeem has written – Saad Dec 22 '14 at 07:31
  • @007 If answer worked for you than you can accept it. – Naeem Dec 22 '14 at 08:33

1 Answers1

4

Any session will remain valid for 2 hours after the last request to QuickBlox. To check a session's expiration date use this next snippet of code:

NSDate *sessionExpiratioDate = [QBBaseModule sharedModule].tokenExpirationDate;
NSDate *currentDate = [NSDate date];
NSTimeInterval interval = [currentDate timeIntervalSinceDate:tokenExpirationDate];
if(interval > 0){
  // recreate session here
}

Check this guide. This feature is available since 1.8 iOS SDK.

Reference: Igor Khomenko

Community
  • 1
  • 1
Naeem
  • 789
  • 1
  • 10
  • 23
  • Thanks Naeem But I saw this link.Ok You mean later I have to use this session, and after two hour I have create newone – Gajendra Rawat Dec 22 '14 at 07:38
  • Yes you have to recreate session. – Naeem Dec 22 '14 at 07:41
  • Hi I fetched remaining time of Quick blox session and I alos ignored creating session if session time is exist but againg login into chat my code is getting crashed. I am getting this ar 2108443 2014-12-22 18:00:40.651 OClub[4587:5507] *** Terminating app due to uncaught exception 'BaseServiceException', reason: 'You have missed the authorization call. Please insert following code inside your application [QBAuth createSessionWithDelegate:self]; – Gajendra Rawat Dec 22 '14 at 12:36
  • 2
    hey Thanks Naeem Actually I have already seen this think but you built up my Confidence :D – Gajendra Rawat Dec 26 '14 at 13:37
  • I am glad that I built up your confidence. Btw your problem solved or not? – Naeem Dec 27 '14 at 05:10