Facebook SDK 4.0 IOS Swift 以编程方式注销用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29374235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook SDK 4.0 IOS Swift Log a user out programmatically
提问by Mina Kolta
In some cases in my application i need to log the user out, but i only have the FBSDKLoginButton instance in my view controller and implementing the
在我的应用程序中的某些情况下,我需要将用户注销,但我的视图控制器中只有 FBSDKLoginButton 实例并实现了
FBSDKLoginButtonDelegate
using
使用
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
I want to pop the login view after logging the user out (destroying Facebook session) Don't know how to use
我想在用户注销后弹出登录视图(破坏 Facebook 会话)不知道如何使用
FBSDKLoginManager.logOut(<#FBSDKLoginManager#>)
I'am working inside a UIViewController and referencing the FBSDKLoginButton through an outlet
我在 UIViewController 内部工作并通过插座引用 FBSDKLoginButton
回答by Mina Kolta
Ok, here is the thing for anyone needs assistance. I managed to log my users out using FBSDKLoginManagerinstance
好的,这是任何需要帮助的人的事情。我设法使用FBSDKLoginManager实例将我的用户注销
Apparently and i don't know if is it documented or not FBSDKLoginManagerwatches
显然,我不知道它是否记录在案 FBSDKLoginManager观看
FBSDKAccessToken.currentAccessToken()
so
所以
let loginManager = FBSDKLoginManager()
loginManager.logOut() // this is an instance function
Logs the user out, what i misunderstood that logOutis not a class function.
将用户注销,我误解了logOut不是类函数。
hope that helps someone!
希望对某人有所帮助!
回答by Zaid Pathan
Swiftyand simple answer for lazy ones like me:
SWIFTY和简单的答案懒惰的我一样:
FBSDKLoginManager().logOut()
回答by Johnny Tsoi
For Swift 3 , Facebook SDK 4.16.0: Using Facebook Swift SDK
对于 Swift 3,Facebook SDK 4.16.0:使用Facebook Swift SDK
LoginManager().logOut()
回答by Javier Calatrava Llavería
Does the same, but in Objective-C:
做同样的事情,但在 Objective-C 中:
[[[FBSDKLoginManager alloc] init] logOut];
[[[FBSDKLoginManager alloc] init] logOut];
Do not forget imports: FBSDKCoreKit/FBSDKCoreKit.h
& FBSDKLoginKit/FBSDKLoginKit.h
不要忘记导入:FBSDKCoreKit/FBSDKCoreKit.h
&FBSDKLoginKit/FBSDKLoginKit.h
回答by King-Wizard
Also, if you have used Parseand the Facebook iOS SDK version >= 4.4.0to sign up or log in a user via Facebook, please use instead:
此外,如果您使用Parse和Facebook iOS SDK 版本 >= 4.4.0通过Facebook注册或登录用户,请改用:
PFUser.logOut()
It will log out the user, delete the session on the Parseback-end side (do not forget to enableParse revocable sessionvia your Parse app settings), plus it will also delete the Facebooksession written on the user device's disk.
它将注销用户,删除Parse后端的会话(不要忘记通过 Parse 应用程序设置启用Parse可撤销会话),此外它还将删除写入用户设备磁盘的Facebook会话。
I hope this answer will help you guys.
我希望这个答案对你们有帮助。