facebook不会在iOS应用程序中正常注销。切换用户

我正在使用fb sdk提供的Facebookloginbutton来实现我的应用程序中的Facebooklogin。当我注销Facebookbutton时,会再次更改为login。但是当我点击它时,Safari浏览器应用程序打开显示“您有alreay授权的应用程序“点击确认或取消。其实我需要在这里的facebooklogin名和密码屏幕。我不能切换用户,直到我重置模拟器。如何重置safari中的内容编程每次我登出,以便login屏幕是每次显示。

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

我用于login的代码如下

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

试试这个用户点击注销并删除存储在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]; } } 

尝试这个…

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

可以为你工作…

并从浏览器清除Cookie …按照这个链接\

http://www.iossnippet.com/snippets/web/how-to-delete-cookies-nshttpcookie-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) { }]; }