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.
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With