1

I have seen a lot of question / answer but not any solution is working.

My problem is that, when we logout from facebook and try to login then it is not asking for username and password, just logged in using the previous user account. Is there any way to logout completely. I have tried following code also but not succeed.

    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];
        }
    }

I have also tried:

-[FBSession closeAndClearTokenInformation]

but same result. Please help me guys!

user3106644
  • 103
  • 8
  • Did you check (domainRange.length > 0)? Is it true in your case? I also suggest to clean NSURLCache with [[NSURLCache sharedURLCache] removeAllCachedResponses]; – Krivoblotsky Mar 29 '14 at 20:29
  • Thank you. I have checked it and it is not working also. No solution on stackoverflow ? – user3106644 Apr 16 '14 at 07:32

2 Answers2

0

Try this code in your logout method:

[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
0

The reason that this occurs is not because the user's session, or token is saved in the app but because the permissions the user allowed have been saved in their facebook account. The storing of an app's permissions happens the first time that a user successfully uses facebook to log into an app. Facebook does this so that users will not have to repeatedly give previously used apps previously granted permissions. To wipe this information from your facebook account, and have the app ask for it's necessary permissions all over again, you have to log into the user's facebook and navigate to Settings-->Apps(apps you use)-->YourAppTitle. Once at YourAppTitle, remove it from your saved apps. Now try to use facebook login within your app, and the app should ask for its necessary permissions.

davetw12
  • 1,815
  • 2
  • 20
  • 27
  • So, technically it is not possible to logout from the facebook completely. If someone wants to change their FB account, then he need to do all the above steps. – user3106644 May 19 '14 at 04:47
  • Well actually, you are effectively logging out when you touch the logout button. It just seems like you weren't completely logged out after logging back in because the permissions that the app needs for you to log back in were saved to your facebook account. Facebook does this so that returning user's (those who previously used facebook to login) of an app can do a quick login using the facebook button. – davetw12 May 22 '14 at 01:21
  • Think about it this way, in a desktop web browser, ever noticed that sometimes your username and password are saved when you visit websites that you've previously logged into? The saving of this data allows for you to simply click the login button to do a quick login. The way that facebook stores the credentials (permissions in the case of an app) necessary for returning users to do a quick login to said app via facebook is basically another version that. – davetw12 May 22 '14 at 01:21
  • Did my answer help you on this matter? – davetw12 Aug 02 '14 at 14:54