How to logout user using Facebook authentication using Swift and iOS?

If you to make the user log out from the app itself programmatically, you can check the following code.

let loginView : LoginManager = LoginManager()
loginView.loginBehavior = FBSDKLoginBehavior.Web

This will open the Facebook login popup in your app in which users can login into your app.

And for the logout, you can call:

  let manager = LoginManager()
  manager.logOut()

This will log out the user from the facebook in the app, after this if you call login method of SDK you will see the login popup again

If you want to clear the profile and token, also call the below code with logout.

 FBSDKAccessToken.setCurrentAccessToken(nil)
 FBSDKProfile.setCurrentProfile(nil)

Leave a Comment