Reset Facebook Token Reference - Facebook SDK 4.0

前端 未结 3 702
轮回少年
轮回少年 2020-12-15 22:30

I previously used the following to clear and reset the Facebook access token

[FBSession.activeSession closeAndClearTokenInformation];

Since

相关标签:
3条回答
  • 2020-12-15 22:53

    Swift 2+ Simple Solution

    FBSDKLoginManager().logOut()
    

    Swift 5+ Simple Solution

    LoginManager().logOut()
    
    0 讨论(0)
  • 2020-12-15 22:54
    FBSDKLoginManager *logMeOut = [[FBSDKLoginManager alloc] init];
    [logMeOut logOut];
    

    or

    [FBSDKAccessToken setCurrentAccessToken:nil];
    [FBSDKProfile setCurrentProfile:nil];
    

    to logout

    Then when you login again, make sure to set:

    login.loginBehavior = FBSDKLoginBehaviorWeb;
    

    Like so:

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    login.loginBehavior = FBSDKLoginBehaviorWeb;
    [login logInWithReadPermissions:@[@"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
             etc...
    }];
    

    I found some info in the docs saying FBSDKLoginBehaviorWeb can be used for "kiosk" apps; which I guess are apps designed to have more than one person log into them routinely.

    One thing to note, this login method creates a modal UIWebView which is set up for portrait mode. I'm not sure if its possible to change this yet.

    0 讨论(0)
  • 2020-12-15 23:08

    In swift you may want to do the following for close the session entirely:

    import FacebookCore
    import FacebookLogin
    
    //...
    
    //in your method:
    
    let fbLoginManager = LoginManager()
    fbLoginManager.logOut()
    AccessToken.current = nil
    UserProfile.current = nil
    
    0 讨论(0)
提交回复
热议问题