我试图以编程方式从Facebook注销而不使用FBSDKLoginButton
我有搜索我怎么办
我找到了这个答案Can we logout facebook programatically
但问题是新的iOS FBSDK版本中不推荐使用FBSession
我的问题是
有没有办法在新的iOS FBSDK版本中清除fb会话?如果有任何方式以编程方式从Facebook注销?
或者如何从FBSDKLoginButton
提前感谢 :)
答案 0 :(得分:87)
您有两种退出方法。 首先,正如Inder Kumar Rathore所建议的
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
其次是将currentAccessToken设置为nil
[FBSDKAccessToken setCurrentAccessToken:nil];
@cookiemonsta希望第二种方法适合你。
答案 1 :(得分:8)
FBSDKLoginManager
是您的需要,它有logOut
方法,但您可能必须使用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];
答案 2 :(得分:7)
Swift版本:
FBSDKLoginManager().logOut()
即使您使用FBSDKLoginManager
登录,也可以使用FBSDKLoginButton
。
答案 3 :(得分:3)
对于Swift 3和4
我想使用这里提到的代码, How to logout user using Facebook authentication using Swift and iOS?
HardikDG提到退出的好答案。 您需要做的是在登录发生之前添加以下行,
FBSDKAccessToken.setCurrent(nil)
FBSDKProfile.setCurrent(nil)
FBSDKLoginManager().logOut()
并在注销时使用代码
allow_user_poisoning
这对我来说非常适合。
答案 4 :(得分:1)
Swift 3和Swift 4:
import FacebookLogin
import FacebookCore
let loginManager = LoginManager()
loginManager.logOut()
答案 5 :(得分:0)
以下将完成这项工作。
import FBSDKLoginKit
LoginManager().logOut()