Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK 4.0 IOS Swift Log a user out programmatically

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

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

FBSDKLoginManager.logOut(<#FBSDKLoginManager#>)

I'am working inside a UIViewController and referencing the FBSDKLoginButton through an outlet

like image 328
Mina Kolta Avatar asked Mar 31 '15 16:03

Mina Kolta


3 Answers

Ok, here is the thing for anyone needs assistance. I managed to log my users out using FBSDKLoginManager instance

Apparently and i don't know if is it documented or not FBSDKLoginManager watches

FBSDKAccessToken.currentAccessToken()

so

let loginManager = FBSDKLoginManager()
loginManager.logOut() // this is an instance function 

Logs the user out, what i misunderstood that logOut is not a class function.

hope that helps someone!

like image 157
Mina Kolta Avatar answered Oct 20 '22 09:10

Mina Kolta


Swifty and simple answer for lazy ones like me:

FBSDKLoginManager().logOut()
like image 35
Mohammad Zaid Pathan Avatar answered Oct 20 '22 10:10

Mohammad Zaid Pathan


For Swift 3 , Facebook SDK 4.16.0: Using Facebook Swift SDK

LoginManager().logOut()
like image 18
JT501 Avatar answered Oct 20 '22 10:10

JT501