OGeek|极客世界-中国程序员成长平台

标题: ios - Firebase Google 登录崩溃 Swift [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:14
标题: ios - 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



Best Answer-推荐答案


我找到了解决办法

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

}

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4