We are using QuickBlox's iOS SDK for chat implementation.
Currently we have only two view controllers 1). Login and 2). UserList
After successful login app moves to UserList view in this view we have Logout button. According to QuickBlox API we have use below method for logout
[QBUsers logOutWithDelegate:self];
on button click and its delegate method :
- (void)completedWithResult:(Result *)result
{
if([result isKindOfClass:[QBUUserLogOutResult class]]) // QuickBlox User Logout result
{
// Success result
if(result.success)
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
}
After successful logout app moves back to login screen.
Problem :
When user clicks on logout and app moves to Login screen and again if user input same user name and password then log prints
Chat App[3183:5903] -[QBChat loginWithUser:] -> return. Already logged in
How to resolve this issue ? OR What is the best practice to implement Login/Logout flow ?
According to SDK reference, exist session, simply user login and login to chat.
1) you need create session. You may create it simply:
[QBAuth createSessionWithDelegate:self];
or with extended request:
QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
extendedAuthRequest.userLogin = @"garry";
extendedAuthRequest.userPassword = @"garrySant88";
[QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];
(If you create session with extended request, pass second action)
2) Perform simply login by
[QBUsers logInWithUserLogin:currentUser password:pass delegate:self]
3) after that for using chat:
[[QBChat instance] loginWithUser:currentUser];
For logout you should perform logout methods in back order.
[[QBChat instance] logout];
after that:
[QBUsers logOutWithDelegate:self];
and:
[QBAuth destroySessionWithDelegate:self];
Recreation of session not necessarily. You can create one session and many times login/logout.