I implemented Facebook Graph API in my iPhone App and I successfully post it in a wall. But each time I end my application and come back it stores my credentials (in Safari I guess as a cookie). It asks my permission with my previous credentials. But at this point I want my Facebook API should prompt for a new username and password login for requesting permission. In simple I want to logout of my Facebook when i select a button in my App.
Asked
Active
Viewed 5,096 times
4 Answers
2
fbGraph.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];
}
}

vihari
- 21
- 2
1
How did you log in to facebook in the first place? If you are using facebook iOS SDK, you just basically have to call [facebook logout:self];
. Otherwise if you're implementing Graph API yourself you just need to clear out your cookies and delete your access token.

Enrico Susatyo
- 19,372
- 18
- 95
- 156
-
you can check out this question: http://stackoverflow.com/questions/1852515/how-to-clear-cookies-from-nshttpcookiestorage-more-then-once – Enrico Susatyo Jan 26 '11 at 10:41
-
I can successfully log out from application. But safari remembers me. So I want totally logout from both my application and safari. How can I do it? – Burak Apr 07 '12 at 13:40
-
@Burak they have different cookies. You can't logout from the app and safari from the app. – Enrico Susatyo Apr 09 '12 at 00:11
-
Ok, then how can I login with different user? – Burak Apr 09 '12 at 10:46
-
The same way you previously log in. – Enrico Susatyo Apr 09 '12 at 12:42
1
when you are call the facebook button at that method last line u wil write this method [facebook logout]

Nag_iphone
- 967
- 7
- 22
0
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
{
[cookies deleteCookie:cookie];
}
These codes are enough to implement logout functionality.
Its working perfectly on my app.

Dilip Manek
- 9,095
- 5
- 44
- 56

ios developer
- 923
- 2
- 12
- 19