The correct way to do this is as follows
NSArray *allAccounts = [SFUserAccountManager sharedInstance].allUserAccounts;
if ([allAccounts count] > 1) {
SFDefaultUserManagementViewController *userSwitchVc = [[SFDefaultUserManagementViewController alloc] initWithCompletionBlock:^(SFUserManagementAction action) {
[self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}];
[self.window.rootViewController presentViewController:userSwitchVc animated:YES completion:NULL];
} else {
if ([allAccounts count] == 1) {
[SFUserAccountManager sharedInstance].currentUser = ([SFUserAccountManager sharedInstance].allUserAccounts)[0];
}
[[SalesforceSDKManager sharedManager] launch];
}
}];
}
- (void)handleUserSwitch:(SFUserAccount *)fromUser
toUser:(SFUserAccount *)toUser
{
[self log:SFLogLevelDebug format:@"SFUserAccountManager changed from user %@ to %@. Resetting app.",
fromUser.userName, toUser.userName];
[self resetViewState:^{
[self initializeAppViewState];
[[SalesforceSDKManager sharedManager] launch];
}];
}
This will allow you to switch users without explicitly logging them out and logging them in again. The key here is to first check if you have more than one user logged into app.
If there is only one user, you can simply logout. If there are multiple users, you don't logout, instead you use SFDefaultUserManagementViewController
to switch to the other user.