Logout of Facebook in app using Facebook ios SDK Logout of Facebook in app using Facebook ios SDK ios ios

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 FBSDKLoginKitfunc logout() {    FBSDKLoginManager().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]                                     initWithTitle:@"Logout"                                    style:UIBarButtonItemStyleBordered                                    target:self                                    action:@selector(logoutButtonWasPressed:)];

and the action method for above added button is

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

Hope this will help you!

Reference

Edit:

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];