Reputation: 1485
I am executing the following code to logout of Facebook from my iPhone application:
if ([mFacebook isSessionValid]) {
[mFacebook logout];
}
This code runs successfully and the delegate is called after this in which I am clearing the access token:
- (void)fbDidLogout
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
But when I again log in to Facebook, it does not ask for username and password.
What am I doing wrong?
Upvotes: 0
Views: 3251
Reputation: 94
Try to log off from the Facebook application. It might just take the token from the Facebook application.
Upvotes: 0
Reputation: 8501
Try this code:
- (void) fbDidLogout {
// Remove saved authorization information if it exists
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]) {
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
}
Don't forget to create an instance for facebook.h
in your AppDelegate.
Upvotes: 0
Reputation: 45
Try adding these at the end of your fbDidLogout block:
mFacebook.accessToken = nil;
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:@"facebook"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
Upvotes: 2
Reputation: 176
Are you using FB mobile Login Dialog? In Facebook.m, add the following code to remove cookies at m.facebook.com domain.
- (void)invalidateSession {
...
NSArray* facebookMCookies = [cookies cookiesForURL:
[NSURL URLWithString:@"https://m.facebook.com"]];
for (NSHTTPCookie* cookie in facebookMCookies) {
[cookies deleteCookie:cookie];
}
...
}
Upvotes: 4
Reputation: 2618
Just add this line to fbDidLogout method
[mFacebook invalidateSession];
This will surely make you logout from Facebook.
Upvotes: 0