ios - Firebase 谷歌登录崩溃 Swift

标签 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().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)
    }

}

关于ios - Firebase 谷歌登录崩溃 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42755246/

相关文章:

ios - 如何在 Firebase 中设置属性?

iphone - 使用导航后退按钮按 iOS Swift 时显示 Admob 插页式广告

ios - UIImageView 实时滤镜在相机预览层上拉伸(stretch)

来自 HAProxy 或 Apache mod_proxy 的 OAuth token 验证

ios - 将数据从 View Controller 传递到第一个细节 Controller ,然后传递到第二个细节 Controller

ios - Xcode 10 上的 FacebookCore Swift 编译器错误

ios - 在 NavigationBar 上方添加 UIView

swift - Firebase 上传图片

oauth-2.0 - OAuth 2 如何使用安全 token 防止重放攻击等行为?

java - 使用某些端点或类的 Azure id_token 有效性