Search code examples
iosswiftdelegatesfacebook-ios-sdk

Facebook button delegate doesn't work correctly


I have facebook button in my viewController. I set it as:

var loginButton: FBSDKLoginButton = FBSDKLoginButton()
loginButton.center = self.view.center
self.view.addSubview(loginButton)

All works, but I want to get response after when user logged in. For it I do:

class LogInSocialController: UIViewController, FBSDKLoginButtonDelegate

and call these 2 functions:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    print("User Logged In")
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    print("User Logged Out")
}

but they are do not response me and I do not get nothing in my logs(the result of prints).

What is the problem?


Solution

  • Just add this line:

    loginButton.delegate = self
    

    And your code look like:

    var loginButton: FBSDKLoginButton = FBSDKLoginButton()
    loginButton.center = self.view.center
    loginButton.delegate = self
    self.view.addSubview(loginButton)