gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:54:52 25 4
gpt4 key购买 nike

我最近更新了当前版本的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com