首页 > 解决方案 > Google SignIn - 始终返回“用户取消了登录流程”

问题描述

我正在使用下面的代码片段通过 google 登录,但总是返回“用户取消了登录流程”

if GIDSignIn.sharedInstance.hasPreviousSignIn() {
            
    logout()
}else {
    guard let clientID = FirebaseApp.app()?.options.clientID else { return }
    let signInConfig = GIDConfiguration.init(clientID: clientID)
    GIDSignIn.sharedInstance.signIn(with: signInConfig, presenting: getWindowTopController()) { user, error in
                
    guard error == nil else { return }
                
    guard let authentication = user?.authentication,let idToken = authentication.idToken else { return }
 }

错误:错误 Domain=com.google.GIDSignIn Code=-5 “用户取消了登录流程。” UserInfo={NSLocalizedDescription=用户取消了登录流程。}

你能帮我解决这个问题吗?

标签: iosswiftauthenticationgoogle-signin

解决方案


试试下面的代码

GIDSignInButton 对象不需要代码中的 addTarget 或链接@IBAction。GIDSignInButton 类已经为我们处理了该操作。

从这里得到它 如何在 iOS 上使用 Sign In with Google 修复“用户取消了登录流程。”?

如果上面的代码不起作用,请尝试下面的代码

自定义 Google 登录按钮 - iOS


推荐阅读