function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dhiru47Dhiru47 

How to logout in salesforce ios native app

Here is where i am fetching the oauth after logginging 

 

- (void) oauthCoordinatorDidAuthenticate:(SFOAuthCoordinator *)coordinator

{

    NSLog(@"Username: %@", coordinator.credentials.userId);

    userId_ = [NSString stringWithString:coordinator.credentials.userId];

   

    [superoauthCoordinatorDidAuthenticate:coordinator];

 

 

}

 

 

Now is there a way to logut progrmatically from the app?

 

Best Answer chosen by Admin (Salesforce Developers) 
Kevin HawkinsKevin Hawkins

This is what the SFAuthenticationManager class is for.  You can call [[SFAuthenticationManager sharedManager] logout], which will clean up app state and raise the kSFUserLogoutNotification (@"kSFUserLogoutOccurred") notification.  If you look at the code in AppDelegate.m from either the native sample apps in the SDK workspace, or in the template app that you generate with forceios, you'll see that, in the init method of the class, the app adds an observer for this notification:

 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutInitiated:) name:kSFUserLogoutNotification object:[SFAuthenticationManager sharedManager]];

 And logoutInitiated:, in this instance, brings up the initial set of view state and prompts the user to login again:

 

- (void)logoutInitiated:(NSNotification *)notification
{
    [self log:SFLogLevelDebug msg:@"Logout notification received.  Resetting app."];
    [self initializeAppViewState];
    [[SFAuthenticationManager sharedManager] loginWithCompletion:self.initialLoginSuccessBlock failure:self.initialLoginFailureBlock];
}

 

 

Your app, of course, can override this behavior in any way you see fit.  But it sounds like this is pretty much the behavior you're hoping to implement in your app, so you should be able to basically copy and paste that code to make it work.

All Answers

jhersh0jhersh0

Two options:

 

Then again, that's not really two options -- I think you'd still have to remove all local data even if you do hit the logout endpoint.

Dhiru47Dhiru47
Is there any way to launch the Loginscreen?

Im ravoking the oauth access some thing like this.

- (void)oauthCoordinatorDidAuthenticate:(SFOAuthCoordinator *)coordinator{
[coordinator revokeAuthentication];
}
jhersh0jhersh0

Sure; same way you presented it to start with.

Dhiru47Dhiru47
sir could you say me the method that takes me to the login screen?
Dhiru47Dhiru47
i tried the method

-(void)logoutofTheApp
{
[[[SFRestAPI sharedInstance] coordinator] revokeAuthentication];
[[[SFRestAPI sharedInstance] coordinator] authenticate];
}

it doesnt popout the login screen , it gives me a warning

2013-09-27 11:12:00.301 CareWeb[21446:c07] oauthCoordinator:didBeginAuthenticationWithView
2013-09-27 11:12:00.302 CareWeb[21446:c07] Warning: Attempt to present <SFAuthorizingViewController: 0x8451c50> on <SFNativeRootViewController: 0x82315b0> whose view is not in the window hierarchy!
Kevin HawkinsKevin Hawkins

This is what the SFAuthenticationManager class is for.  You can call [[SFAuthenticationManager sharedManager] logout], which will clean up app state and raise the kSFUserLogoutNotification (@"kSFUserLogoutOccurred") notification.  If you look at the code in AppDelegate.m from either the native sample apps in the SDK workspace, or in the template app that you generate with forceios, you'll see that, in the init method of the class, the app adds an observer for this notification:

 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutInitiated:) name:kSFUserLogoutNotification object:[SFAuthenticationManager sharedManager]];

 And logoutInitiated:, in this instance, brings up the initial set of view state and prompts the user to login again:

 

- (void)logoutInitiated:(NSNotification *)notification
{
    [self log:SFLogLevelDebug msg:@"Logout notification received.  Resetting app."];
    [self initializeAppViewState];
    [[SFAuthenticationManager sharedManager] loginWithCompletion:self.initialLoginSuccessBlock failure:self.initialLoginFailureBlock];
}

 

 

Your app, of course, can override this behavior in any way you see fit.  But it sounds like this is pretty much the behavior you're hoping to implement in your app, so you should be able to basically copy and paste that code to make it work.

This was selected as the best answer
Dhiru47Dhiru47
I couldnt find a class like SFAuthenticationManager
Kevin HawkinsKevin Hawkins

Which version of the SDK are you using?

Dhiru47Dhiru47
I think i am using version 1.0 and this intial version from year 2011
Gaurav KheterpalGaurav Kheterpal

Unless there's a good reason to use an old version of the Mobile SDK, you should use the latest stable version (2.x).