Logout from Facebook programmatically iOS

前端 未结 6 1015
不思量自难忘°
不思量自难忘° 2020-12-29 03:53

I am trying to logout from Facebook programmatically without using FBSDKLoginButton i had search how could I do i found this answer Can we logout facebook pro

相关标签:
6条回答
  • 2020-12-29 04:10

    Swift version:

    FBSDKLoginManager().logOut()
    

    You can use FBSDKLoginManager even if you logged in with FBSDKLoginButton.

    0 讨论(0)
  • 2020-12-29 04:16

    FBSDKLoginManager is your need, it has logOut method but you might have to use your custom login

    e.g.

    FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
    [loginManager logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
      if (error) {
        // Process error
      } else if (result.isCancelled) {
        // Handle cancellations
      } else {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if ([result.grantedPermissions containsObject:@"email"]) {
          // Do work
        }
      }
    }];
    
    //then logout
    [loginManager logOut];
    
    0 讨论(0)
  • 2020-12-29 04:19

    Swift 3 and Swift 4:

    import FacebookLogin
    import FacebookCore
    
    let loginManager = LoginManager()
    loginManager.logOut()
    
    0 讨论(0)
  • 2020-12-29 04:29

    The following would do the job.

    import FBSDKLoginKit
    
    LoginManager().logOut()
    
    0 讨论(0)
  • 2020-12-29 04:30

    You have two methods to logout. First, as suggested by Inder Kumar Rathore

    FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
    [loginManager logOut];
    

    Second is by setting the currentAccessToken to nil

    [FBSDKAccessToken setCurrentAccessToken:nil];
    

    @cookiemonsta hope second method works for you.

    0 讨论(0)
  • 2020-12-29 04:30

    For Swift 3 and 4

    I would like to use the code mentioned over here, How to logout user using Facebook authentication using Swift and iOS?

    where HardikDG mentioned a good answer for logout. what you need to do is add below line before the login happen,

    fbLoginManager.loginBehavior = FBSDKLoginBehavior.web
    

    and while logout use below code

    FBSDKAccessToken.setCurrent(nil)
    FBSDKProfile.setCurrent(nil)
    FBSDKLoginManager().logOut()
    

    this works perfectly for me.

    0 讨论(0)
提交回复
热议问题