Facebook无法在iOS App.Cannot Switch用户中正确注销



我正在使用FB SDK提供的Facebook登录按钮来在我的应用中实现Facebook登录。当我登录Facebook按钮时,请再次更改为登录。单击它,Safari应用程序打开显示"您已授权AlreAy"单击确认或取消。实际上,我需要在此处使用Facebook登录和密码屏幕。我不能切换用户,直到我重置模拟器。如何重置Safari中的内容每次注销时,以编程方式以每次显示登录屏幕。

请注意,当我手动清除Safari的网站数据时,它再次显示登录页面。可以通过编程完成。

我正在使用登录的代码如下

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

尝试此IT用户单击注销,然后删除存储在UserDefault/Cookie中的所有键

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

尝试这个...

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

可能对您有用...

,对于浏览器的清晰饼干...请遵循此链接

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

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

使用以下代码

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

最新更新