I\'m trying to implement Facebook login in my iOS app, using Parse.
let permissionsArray = [\"public_profile\", \"email\"]
PFFacebookUtils.logInInBackgroun
Fixed it. This issue was caused by logging in with Parse and with FBSDKLoginButton.
Here's what I was doing:
//in my UI setup code:
let fbLoginButton = FBSDKLoginButton()
fbLoginButton.addTarget(self, action: "fbButtonTouched:", forControlEvents: UIControlEvents.TouchUpInside)
....
func fbButtonTouched() {
let permissionsArray = ["public_profile", "email"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
{ (user: PFUser?, error: NSError?) in
if let user = user {
//we logged in!
}
else {
//login error!
}
}
}
I found out (the hard way) that tapping a FBSDKLoginButton attempts to log the user in! There was no need to also log the user in using PFFacebookUtils.logInInBackgroundWithReadPermissions. So I just got rid of fbButtonTouched() and I could happily log in.
So what happened was that I was attempting two logins at the same time, which the simulator was happy with, but not the device.
If you want to know why, it's because the login authentication challenge it received did not correspond to the one it was expecting because it received the one from the first log in attempt after it had sent the one from the second log in attempt and was therefore waiting for the second log in attempts' authentication challenge.
The documentation for FBSDKLoginButton doesn't currently mention anything about the fact that tapping it initiates the log in flow, and because it's a subclass of UIButton, you'd think that you ought to addTarget to it and implement the login flow yourself. And having two logins at the same time leads to a misleading FBSDKLoginBadChallengeString. Recipe for disaster...
EDIT: The documentation has been updated correspondingly:
FBSDKLoginButtonworks with[FBSDKAccessToken currentAccessToken]to determine what to display, and automatically starts authentication when tapped (i.e., you do not need to manually subscribe action targets).
(my emphasis)