Facebook Login Button not Changing to Logout button Immediate after Login in swift

269 Views Asked by At

I am Working on Xcode 9.2 Swift 4.0 using FacebookSDKs-iOS-20160316 for Facebook Login Authentication Integration . My storyboard is empty .

On Running

Facebook Login button is coming on an app

When clicked Facebook login page comes, after successful login

Permission for my app is asked, When allowed following page comes

Page after allowing access to my app

When I click on done button of this page

I am redirected to my storyboard , and this time also same login button is there , my login button is not changed to Logout. On clicking it again following page comes:
After clicking Login button again This is happening every Time. Please help me.

Things I have tried:

Restarted the Simulator

Restarted the Xcode

Changed Simulator

//My View Controller is having code:

class ViewController: UIViewController,FBSDKLoginButtonDelegate{

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWithresult:     
FBSDKLoginManagerLoginResult!, error: Error!) 
 {
 print("Logged in")
 }
    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) 
{
    print("Logged out")
}

let loginManager: FBSDKLoginManager = FBSDKLoginManager()
override func viewDidLoad() 
  {
    super.viewDidLoad()
    let button = FBSDKLoginButton()
    button.center = self.view.center
    self.view.addSubview(button)
    button.delegate = self
  }
}
1

There are 1 best solutions below

0
AzeTech On

Try this function as for logout along with login.

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
        print("User is looged out")
    }