I am using all the latest and greatest : XCode 13.2.1, Salesforce Mobile SDK 10.
I am writing a native iOS Swift app and I wish to DEFER the Salesforce login to a point in the application that makes sense. (Perhaps the user doesn't even want to connect to Salesforce :) )
It's all very easy. I simply defer the call to AuthHelper.loginIfRequired() to wherever it makes sense for me.
OK, very good.
Now I want the same ability if the user logs off yes? I do NOT want the Login Page in my face just because they log off. I want to decide what happens.
Hmmmm?? I call UserAccountManager.shared.logout() to logout (please correct me if that is the wrong thing to do). It appears (from the logs) to do what I think it should do, and the handleLogout() method of AuthHelper is invoked (not by me of course, by the SDK). The code (in handleLogout()) tries to help?? and decides that if there are no current active users left, then it will call AuthHelper.loginIfRequired() on my behalf :( OK, that's pretty solid logic, if that's what I want, but I don't!! :) I want to control if/when the login flow should be initiated.
I can't figure out how to do it :(
I can of course register call backs for 'forLogoutNotifications' and all that jazz works, but I cannot stop the call to the existing AuthHelper.handleLogout() method from executing. I want my own version :)
Yes, I'm an iOS newbie, and perhaps there is a simple answer, but I don't get it :( You can see the 'problem child' line of code (in the SDK AuthHelper) at the bottom there :(
Thanks in advance for any iOS dudes helping me!!
+ (void)handleLogout:(UIScene *)scene completion:(void (^)(void))completionBlock {
// Multi-user pattern:
// - If there are two or more existing accounts after logout, let the user choose the account
// to switch to.
// - If there is one existing account, automatically switch to that account.
// - If there are no further authenticated accounts, present the login screen.
//
// Alternatively, you could just go straight to re-initializing your app state, if you know
// your app does not support multiple accounts. The logic below will work either way.
NSArray *allAccounts = [SFUserAccountManager sharedInstance].allUserAccounts;
if ([allAccounts count] > 1) {
SFDefaultUserManagementViewController *userSwitchVc = [[SFDefaultUserManagementViewController alloc] initWithCompletionBlock:^(SFUserManagementAction action) {
[[[SFSDKWindowManager sharedManager] mainWindow:scene].window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}];
[[[SFSDKWindowManager sharedManager] mainWindow:scene].window.rootViewController presentViewController:userSwitchVc animated:YES completion:NULL];
} else {
if ([allAccounts count] == 1) {
[[SFUserAccountManager sharedInstance] switchToUser:([SFUserAccountManager sharedInstance].allUserAccounts)[0]];
if (completionBlock) {
completionBlock();
}
} else {
[self loginIfRequired:scene completion:completionBlock];
}
}
}