5

I have facebook login in my iphone app using facebook sdk-3.1 .After login it will get in to my app and there I didnot give any logout button .so,when we click button login with facebook I will get the previous user facebook account .

Inorder to resolve this problem iam giving button logout.

how can I logout facebook programmatically on clicking button

am giving login like this

-(IBAction)Login:(id)sender
{

    appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
     appDelegate.getActionForLoginbtn=@"LoginwithFB";
       [appDelegate openSessionWithAllowLoginUI:YES];
}


-(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI{


    NSArray *permissions=[[NSArray alloc]initWithObjects:@"email", nil];
    return[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
        [self sessionStateChanged:session state:state error:error];
    }];
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user2197875
  • 171
  • 3
  • 12

2 Answers2

20

Use this code:

if (FBSession.activeSession.isOpen)
{
    [FBSession.activeSession closeAndClearTokenInformation];
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sumit Mundra
  • 3,891
  • 16
  • 29
5

Swift version

import FBSDKLoginKit

FBSDKLoginManager().logOut()

Using FBSDK 4.4

#import <FBSDKLoginKit/FBSDKLoginManager.h>

then use this code to logout.

FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
[manager logOut];

hope this will help :)

M.Yessir
  • 202
  • 3
  • 11
  • I see how the function works, but I guess it's a little bit strange that we need to create instance. Why they did not implement it as a static method. `setCurrentAccessToken` and `setCurrentProfile` are static as well =) – Matrosov Oleksandr Feb 18 '16 at 17:19