Search code examples
iosfacebookswiftfacebook-ios-sdk

Forget previously logged in facebook user?


When I promt the user to log in with their facebook account I do it like this:

FBSession.openActiveSessionWithReadPermissions(["email"], allowLoginUI: true) { (session, state, error) -> Void in
        if error == nil && state == .Open {
            FBRequest.requestForMe().startWithCompletionHandler({ (connection, data_, error) in
                println("Facebook data: ")
                if error == nil {
                    let facebookInfo = data_ as NSDictionary

                }
            })
        }
        else {
            self.SuperVC!.presentAlertView("Error", message: "Could not connect with facebook.", decline: "Ok", others: [])
        }

Now, when its the first time logging in the user can enter their email and password... but the next time its not possible to do so, it remembers the previous user even if I clear token info like this:

FBSession.activeSession().closeAndClearTokenInformation()

I clear the token before promting to login, for testing purposes.

It only forgets if I reset the entire app, by deleting it or in the simulator 'Reset contents and settings'

Lets say that another user wants to log in on the same device, it is not possible.

How do I make it forget the previous user?


Solution

  • I solved my issue by using another method for promting the user credentials.

    I used

    FBSession.activeSession().openWithBehavior(FBSessionLoginBehavior.ForcingWebView, completionHandler:{
        // Stuff...
    }
    

    With the .ForcingWebView it always starts over and promting the users ceredntials.