Firebase和Facebook身份验证

时间:2016-06-03 13:29:06

标签: swift firebase facebook-authentication

我正在尝试使用Firebase和Facebook登录并且它正在运行,但是当Facebook页面打开并且您关闭它而未登录它会抛出错误并说“致命错误:在解开可选值时意外地发现了nil” 突出显示为导致错误的行是let credential .... 这是我的代码:

// Login button is pressed
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

        if let error = error {

          print(error.localizedDescription)

        } else {

            let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
            FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in

                if let error = error {

                    print(error.localizedDescription)

                } else {

                    self.performSegueWithIdentifier("loginSegue", sender: self)
                    print("Login complete")

                }
            }
        }
    }

有人可以帮帮我吗?感谢

1 个答案:

答案 0 :(得分:1)

如果您有用户,或者用户可能取消了注册

,您还需要检查
if let user = user {

 } else {
   print("Uh oh. The user cancelled the Facebook login."))
}