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

大兔子大兔子 提交于 2020-01-13 05:53:33

问题


i am using the facebook login button provided by the fb sdk for implementing the facebook login in my app.When i am logging out the facebook button does change back to login again.but when i click on it,the safari app opens showing "you have alreay authorised the app"click confirm or cancel.Actually i needed the facebook login and password screen here.I cannot switch user until i reset the simulator.how to reset the contents in safari programmatically each time i logout so that the login screen is shown each time.

Please note that when i clear the website data of safari manually it shows the login page again.can it be done programmatically.

code i am using for login is as follows

//creating the login button
 FBLoginView *loginView =
    [[FBLoginView alloc] initWithReadPermissions:
     @[@"public_profile", @"email", @"user_friends"]];
    loginView.frame=CGRectMake(50, 500, 225, 55);
    loginView.delegate=self;
    [self.view addSubview:loginView];

//delegate method when logged in
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {


    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:[user objectForKey:@"id"] forKey:@"LoggedInUserID"] ;


    [self checkandsaveNewUserInBackend:user];




  [self performSegueWithIdentifier:@"Login" sender:self];

}




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

    [FBSession.activeSession closeAndClearTokenInformation];


    [self.navigationController popToRootViewControllerAnimated:YES];
}

回答1:


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



回答2:


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/




回答3:


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


来源:https://stackoverflow.com/questions/30207893/facebook-does-not-logout-properly-in-ios-app-cannot-switch-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!