2

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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
ipraba
  • 16,485
  • 4
  • 59
  • 58

4 Answers4

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
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