Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue switching FB users in FBSDK in Swift

I have an app which uses FB login inside the app to gather a users FB id which I use to create a link to their FB page like so:

    @IBAction func saveFacebookDidTap(_ sender: Any) {
    if sharingFacebook == false {
        if  FBSDKAccessToken.current() == nil {
            print("no token")
        }
            login.logIn(withReadPermissions: ["public_profile"], handler: { (result, error) -> Void in

            if error == nil && !(result?.isCancelled)! {
                let fbloginresult : FBSDKLoginManagerLoginResult = result!

                if fbloginresult.grantedPermissions.contains("public_profile") {
                    print("success")
                    let parameters = ["fields" : "id"]

                    if FBSDKAccessToken.current() != nil {

                        self.facebookButton.setTitle("Remove Facebook from your Profile", for: [])
                        self.sharingFacebook = true
                    FBSDKGraphRequest(graphPath: "me", parameters: parameters).start { (connection, result, error) -> Void in

                        if error != nil {
                            return
                        }

                        let data:[String:AnyObject] = result as! [String : AnyObject]

                        if let id = data["id"] as? NSString{

    //do stuf with the id

I also allow the user to remove this FB link like so:

    else {
        self.sharingFacebook = false
        self.facebookButton.setTitle("Add Facebook to your Profile", for: [])

        FBSDKLoginManager().logOut()

    }

I am having an issue with the FB login page. When the user clicks to add their FB, I am seeing a page that says "You previously logged in to "app name" with Facebook. Would you like to continue?" I am not seeing the fields which let me enter email and password. Any ideas what I could be missing?

like image 567
Sente Avatar asked Oct 08 '17 18:10

Sente


2 Answers

I was having a similar problem. The cause is explained here: How to completely Logout of Facebook SDK Auth in iOS App

I was able to get around this issue by setting the Login Behavior, i.e.

LoginManager.setLoginBehavior('web');

before initiating login.

like image 60
chez.mosey Avatar answered Nov 07 '22 10:11

chez.mosey


I had this issue when Safari was caching the Facebook login credentials. Went to Settings...Safari...Clear History and Data. Solved it.

like image 22
Joel Avatar answered Nov 07 '22 10:11

Joel