Logout of Facebook in app using Facebook ios SDK

I have integrated Facebook login in my app and therfore user can login with both my app account and also Facebook and do corresponding actions.For Facebook integration I have added Facebook SDK.Now when Logout button is clicked in my app it has to clear all the credentials of Facebook Account.I have gone for :

  [appDelegate fbDidlogout]; 
    FBSession* session = [FBSession activeSession];
    [session closeAndClearTokenInformation];
    [session close];
    [FBSession setActiveSession:nil];


But when I again click on button I m redirected directly to my account without going to Facebook Login page.

  • How to convert .xcarchive to .ipa for client to submit app to app store using Application Loader
  • OCUnit test cases not running
  • NSXMLParser doesn't ignore CDATA
  • Twitter Post iOS6 'Cancel' button issue
  • What's the difference between “Architectures” and “Valid Architectures” in Xcode Build Settings?
  • Xcode now generates an empty category. Why?
  • How can I logout of Facebook?

    4 Solutions Collect From Internet About “Logout of Facebook in app using Facebook ios SDK”

    Using new Facebook SDK login kit just write below line and thats it..

    [[FBSDKLoginManager new] logOut];

    If using swift, make sure to have the necessary imports

    import FBSDKLoginKit
    func logout() {

    For logout you should try this

    you can add the Logout button on Navigation Controller (Top Right Corner) in viewDidLoad method

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 

    and the action method for above added button is

    -(void)logoutButtonWasPressed:(id)sender {
        [FBSession.activeSession closeAndClearTokenInformation];

    Hope this will help you!



    As you asked why its not asking for UserName and Password,So the reason is :

    When we integrate Facebook SDK in our app and try to login, it automatically check two places (to make sure we have already logged-in Facebook or not)

    1. First of all It checks whether we have already logged-in into Facebook Native app which is installed on this device.

    2. then It checks whether we have saved our FaceBook UserName and Password in Device Settings.

    If both places we haven’t logged-in then It will ask UserName and Password in application

    you can check Facebook account setup in Device Settings as shown in below screen shot,

    Press Home Button –> Settings –>Facebook

    enter image description here

    FBSDK is doing logout like this:

      [FBSession.activeSession closeAndClearTokenInformation];
      FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
      [login logOut];

    In your postButtonClicked write following if else :

        _session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
        [_session resume];
        posting = YES;
        showSlideShow = 1;
        if (_facebookName != nil)
            [self logoutButtonClicked];
        if (![_session isConnected])
            self.loginDialog = nil;
            _loginDialog = [[FBLoginDialog alloc] init];
            [_loginDialog show];
        else {
            self.loginDialog = nil;
            _loginDialog = [[FBLoginDialog alloc] init];
            [_loginDialog show];