facebook does not logout properly in ios app.cannot switch users

本秂侑毒 提交于 2019-12-04 15:46:34

try this it user clicks on logout and remove all keys stored in userdefault/cookies

  NSLog(@"Logged out facebook");
 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];
   }
}

Try this...

        [FBSession.activeSession closeAndClearTokenInformation];
        [FBSession.activeSession close];
        [FBSession setActiveSession:nil];  

May work for you...

And for clear cookies from browser...follow this link \

http://www.iossnippet.com/snippets/web/how-to-delete-cookies-nshttpcookie-in-objective-c-ios/

In the

//logout code
- (IBAction)logoutButtonPressed:(id)sender { 

Use following code

 if (FBSession.activeSession.state == FBSessionStateOpen
        || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {



    // Close the session and remove the access token from the cache
    // The session state handler (in the app delegate) will be called automatically
    [FBSession.activeSession closeAndClearTokenInformation];

    // If the session state is not any of the two "open" states when the button is clicked
} else {
    // Open a session showing the user the login UI
    // You must ALWAYS ask for public_profile permissions when opening a session
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
             }];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!