GoogleSignIn:GIDSignInResult 类型的值没有成员“身份验证”

问题描述 投票:0回答:1

我最近更新了当前版本的 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()
//                }
//            }
//        }
    }
ios swift xcode cocoapods google-signin
1个回答
0
投票

旧的闭包从

user, error in
更新为
authentication, error in
其中
authentication
的类型是
GIDSignInResult

func googleSignInAction(){
    guard let clientID = FirebaseApp.app()?.options.clientID else { return }
    let config = GIDConfiguration(clientID: clientID)
    
    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()
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.