Firebase Google 登录崩溃 Swift

阿纳夫·乔拉
@IBAction func GoogleLoginDidTapped(_ sender: Any) {
    print("Google login completed")
    try? GIDSignIn.sharedInstance().signIn()
   try? GIDSignIn.sharedInstance().uiDelegate = self
    try? GIDSignIn.sharedInstance().delegate = self

}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
  try?  auth(authentication: user.authentication)

}
func auth(authentication: GIDAuthentication)
{
    let credential = FIRGoogleAuthProvider.credential(withIDToken: authentication.idToken , accessToken: authentication.accessToken)


    FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
        if error != nil{
            print(error?.localizedDescription)
        }
        else
        {


            print(user?.email)

            print(user?.displayName)

            x = true
            name = (user?.displayName)!
            self.movespecial()
        }

    })
}

我可以登录,但是当谷歌窗口打开时,如果我点击完成,应用程序就会崩溃。有人能帮帮我吗?提前致谢。

我已经在这个应用程序上工作了一段时间,这是最后一步。我得到的错误是

fatal error: unexpectedly found nil while unwrapping an Optional value
阿纳夫·乔拉

我找到了解决方案

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if error == nil
    {
        auth(authentication: user.authentication)
    }
    else
    {
        print(error.localizedDescription)
    }

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章