Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Firebase Google登录崩溃Swift_Ios_Swift_Oauth 2.0_Firebase Authentication_Google Signin - Fatal编程技术网

Ios Firebase Google登录崩溃Swift

Ios Firebase Google登录崩溃Swift,ios,swift,oauth-2.0,firebase-authentication,google-signin,Ios,Swift,Oauth 2.0,Firebase Authentication,Google Signin,我可以登录,但当谷歌窗口打开时,如果我点击“完成”,应用程序就会崩溃。谁能帮帮我吗?提前谢谢 我已经在这个应用程序上工作了一段时间,这是最后一步。 我得到的错误是 @IBAction func GoogleLoginDidTapped(_ sender: Any) { print("Google login completed") try? GIDSignIn.sharedInstance().signIn() try? GIDSignIn.sharedInstance()

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

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

@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

哪里是错误?@javimuu我得到的错误是致命错误:在展开可选值时意外发现nil查看返回的错误,似乎是在
name=(user?.displayName)
,由于未知原因,用户返回
nil
,或者它没有
displayName
属性。这也可能是由于您的Firebase配置造成的。@AlexandreLara我应该如何处理我的Firebase配置它不是用户显示名我认为您应该做的第一件事是检查
user
是否为nil,您可以使用
guard let
表达式来完成,例如:
guard let myUser=user else{print(“user is nil”)return}
。如果用户不是nil,请尝试转到您的Firebase帐户,下载一个新的
google services.json
文件并将其放入您的项目中。在“身份验证”部分,检查您正在使用的登录提供程序是否已启用。
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if error == nil
    {
        auth(authentication: user.authentication)
    }
    else
    {
        print(error.localizedDescription)
    }

}