以编程方式从iOS注销

Ahd*_*wan 31 facebook objective-c ios facebook-sdk-4.0

我试图以编程方式从Facebook注销而不使用FBSDKLoginButton 我有搜索我怎么能找到这个答案我们可以以编程方式注销facebook 但问题是FBSession在新的iOS FBSDK版本中已弃用

我的问题是有没有办法在新的iOS FBSDK版本中清除fb会话?如果有任何方式以编程方式从Facebook注销?或者如何从中调用注销操作FBSDKLoginButton

提前感谢:)

mar*_*ars 88

您有两种注销方法.首先,正如Inder Kumar Rathore所建议的那样

FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
Run Code Online (Sandbox Code Playgroud)

其次是将currentAccessToken设置为nil

[FBSDKAccessToken setCurrentAccessToken:nil];
Run Code Online (Sandbox Code Playgroud)

@cookiemonsta希望第二种方法适合你.

  • 您还应该调用:[FBSDKProfile setCurrentProfile:nil]因为logOut也调用它.在此解释:https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginManager/ (2认同)
  • Facebook在注销方法中内部调用`[FBSDKAccessToken setCurrentAccessToken:nil]`,无需显式调用它.在本文档中提到:https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginManager (2认同)

Ind*_*ore 8

FBSDKLoginManager是你的需要,它有logOut方法,但你可能必须使用自定义登录

例如

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];
Run Code Online (Sandbox Code Playgroud)


Cma*_*mar 7

Swift版本:

FBSDKLoginManager().logOut()
Run Code Online (Sandbox Code Playgroud)

FBSDKLoginManager即使您已登录,也可以使用FBSDKLoginButton.