How do I manage Quick Blox Session?
I have a question about the Quick blox API. I will now register a user using the code below.
[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 the above code, I first create a session and register a new user, then I am the login user. During registration, I was not logged in to QuickBlox chat during registration, but later when I log into Quick blox chat in another module, I still need to create a new session or I need to maintain a new session.
+3
source to share
1 answer
Any session will remain valid for 2 hours after the last QuickBlox request. To check the session expiration, use the following code snippet:
NSDate *sessionExpiratioDate = [QBBaseModule sharedModule].tokenExpirationDate;
NSDate *currentDate = [NSDate date];
NSTimeInterval interval = [currentDate timeIntervalSinceDate:tokenExpirationDate];
if(interval > 0){
// recreate session here
}
Check out this guide. This feature is available with iOS 1.8 SDK.
Help: Igor Khomenko
+4
source to share