ios - 谷歌登录 : value of type GIDSignInResult has no member 'authentication'

标签 ios swift xcode cocoapods google-signin

我最近更新了当前版本的 GoogleSignIn,但找不到解决我面临的问题的方法。我收到的错误是:类型“GIDSignInResult”的值没有成员“身份验证”

func googleSignInAction(){
        guard let clientID = FirebaseApp.app()?.options.clientID else { return }
        let config = GIDConfiguration(clientID: clientID)
        
        GIDSignIn.sharedInstance.signIn(withPresenting: self) { user, error in
            if let error = error {
                print("There is an error signing the user in ==> \(error)")
                return
            }

            guard let authentication = user?.authentication, let idToken = authentication.idToken else { return }
            let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)

            Auth.auth().signIn(with: credential) { authResult, error in
                if error != nil {
                    print(error)
                } else {
                    self.email = authResult?.user.email
                    self.photoURL = authResult?.user.photoURL!.absoluteString
                    self.checkIfUserAccountExists()
                }
            }
        }
        
        //PRevious code that worked
//        GIDSignIn.sharedInstance.signIn(with: config, presenting: self) { [unowned self] user, error in
//
//            if let error = error {
//                print("There is an error signing the user in ==> \(error)")
//                return
//            }
//
//            guard let authentication = user?.authentication, let idToken = authentication.idToken else { return }
//            let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)
//
//            Auth.auth().signIn(with: credential) { authResult, error in
//                if error != nil {
//                    print(error)
//                } else {
//                    self.email = authResult?.user.email
//                    self.photoURL = authResult?.user.photoURL!.absoluteString
//                    self.checkIfUserAccountExists()
//                }
//            }
//        }
    }

最佳答案

旧的闭包已从 user, error in 更新为 authentication, error in,其中 authentication 的类型为 GIDSignInResult

func googleSignInAction() {
    
    GIDSignIn.sharedInstance.signIn(withPresenting: self) { authentication, error in
        if let error = error {
            print("There is an error signing the user in ==> \(error)")
            return
        }
        guard let user = authentication?.user, let idToken = user.idToken?.tokenString else { return }
        let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: user.accessToken.tokenString)
        
        Auth.auth().signIn(with: credential) { authResult, error in
            if error != nil {
                print(error)
            } else {
                self.email = authResult?.user.email
                self.photoURL = authResult?.user.photoURL!.absoluteString
                self.checkIfUserAccountExists()
            }
        }
    }
}

关于ios - 谷歌登录 : value of type GIDSignInResult has no member 'authentication' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76284373/

相关文章:

ios - Swift:如果我在变量中有实例的名称,如何创建类的实例?

swift - 使用 NSUserDefaults 检索对象数组

ios - 如何节省音频时间?

ios - 在类 AppDelegate 上发出 SIGABRT 信号

ios - i386 架构在 MacOS 错误中弃用

ios - 完全免费的 iOS 应用是否需要应用商店收据验证?

objective-c - 具有不同数组设置的 UITableView 多个部分

ios - 在 Xcode 6 中使用 AutoLayout 约束模拟方面适合行为

iphone - iOS 客户端、Facebook API 和服务器之间的安全通信

ios - 如何通过Ruby(或Xcodeproj)获取目标版本