Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift iOS App Facebook SDK 4.0 on login/logout methods not executing

So I have been working on a swift iOS app which uses Facebook and its SDK. I have the login button working and it saves information properly however I am unable to run code upon a successful login/logout. The dedicated functions:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    println("User Logged In")
    backButton.hidden = false
    loginText.text = "Thanks for Logging In"
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    println("User Logged Out")
    loginText.text = "Please Login"
    backButton.hidden = true
}

do not run at all when the user logs in and out. Any help would be greatly appreciated, if need be I can upload the rest of the code. I am having the problem in two different view controllers not just this one, both of which have their own class.

like image 740
Wyler Avatar asked Dec 06 '25 11:12

Wyler


1 Answers

Assign delegate to your FBSDKLoginButton.

class ViewController: UIViewController,FBSDKLoginButtonDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        var loginButton = FBSDKLoginButton()
        loginButton.delegate = self
        loginButton.frame = CGRectMake(100, 100, 150, 40)
        self.view.addSubview(loginButton)
}

Once user is logged in the following delegate method is called.

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

        println("User Logged In")
    }

Once user is logged out the following delegate method is called.

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {

    println("User Logged Out")
}
like image 188
Dheeraj Singh Avatar answered Dec 08 '25 02:12

Dheeraj Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!