Reputation: 171
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];
}];
}
Upvotes: 5
Views: 6261
Reputation: 3901
Use this code:
if (FBSession.activeSession.isOpen)
{
[FBSession.activeSession closeAndClearTokenInformation];
}
Upvotes: 20
Reputation: 222
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 :)
Upvotes: 5