facebook无法在ios app.cannot切换用户

时间:2015-05-13 07:05:50

标签: ios facebook facebook-ios-sdk

我正在使用fb sdk提供的facebook登录按钮在我的应用程序中实现facebook登录。当我退出时,facebook按钮确实改回登录状态。但是当我点击它时,safari应用程序打开显示"你已经授权应用程序"点击确认或取消。实际上我需要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];
}

3 个答案:

答案 0 :(得分:1)

试试这个......

        [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/

答案 1 :(得分:1)

尝试此操作,用户点击注销并删除存储在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 :(得分:1)

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