How do I close aCtive Session Of the Facebook-iOS-Sdk
each time when i start my app either after killing app it gives me the previous login session details. When I click on the facebook Button .I have used everything [appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation]
..but active session still not been close..how do i close the Previous session data on clicking.
I use the below code to clear but whenever I click on the facebook button to start new session..it gives me back the previous credentials.
- (IBAction)buttonClickHandler:(id)sender {
appDelegate = [[UIApplication sharedApplication]delegate];
// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession=nil;
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession=nil;
[FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// and here we make sure to update our UX according to the new session state
NSLog(@" state=%d",state);
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
userInfo = @"";
// Example: typed access (name)
// - no special permissions required
userInfo = user.username;
NSLog(@"string %@", userInfo);
[self checkfacebook];
}];
}]; }
}
and in ViewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[FBSession.activeSession close];
FBSession.activeSession=nil;
}
}
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
}
The Facebook SDK enables: Facebook Login - Authenticate people with their Facebook credentials. Share and Send dialogs - Enable sharing content from your app to Facebook. App Events - Log events in your application.
The Facebook SDK includes code to access Apple's Advertising Identifier (IDFA), but that code is only executed in certain situations.
hi Christien may be bellow two link its help's you please refur this two link of developers.facebook
http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/
http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];
you can also check this two question related your issue :-
Facebook graph api log out not working
Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation" method no working
hope its helps you
After calling
[FBSession.activeSession closeAndClearTokenInformation];
use following to clear cookies. It worked for me!
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in
[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[cookies deleteCookie:cookie];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With