如何通过iOS上的“通过Google登录”解决“用户取消了登录流程。”

时间:2019-02-21 12:12:29

标签: ios swift google-signin

我正在将iOS Firebase SDK与Google登录集成。当用户点击GIDSignIn按钮时,该应用会显示一条警告,显示"MyAPP" want to use Google.com for Sign in,但该警告会很快消失。我在didSignInFor user: GIDGoogleUser方法中遇到的错误如下:

2019-02-21 16:54:13.104279+0530 MyApp[18743:185089] [Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFAuthenticationViewController: 0x7fa327945800>)
[DEBUG] Google sign-in error: Error Domain=com.google.GIDSignIn Code=-5 "The user canceled the sign-in flow." UserInfo={NSLocalizedDescription=The user canceled the sign-in flow.}

我遵循了Authenticate Using Google Sign-In on iOS文档。

我也尝试过Google Sign-In crashes on iOS 9 attempting to call canOpenURL的答案,但是没有用。

AppDelegate也实现了GIDSignInUIDelegate

如果我从GIDSignInButton to UIButton更改按钮,它可以工作,但是样式丢失。

3 个答案:

答案 0 :(得分:2)

如果您试图在GIDSignIn.sharedInstance()?.signIn()中运行@IBAction。您可以在登录前运行GIDSignIn.sharedInstance()?.presentingViewController = self,而不是在viewDidLoad()内部运行。

@IBAction func googleLogin(_ sender: UIButton) {
    GIDSignIn.sharedInstance()?.presentingViewController = self
    GIDSignIn.sharedInstance()?.signIn()
}

答案 1 :(得分:1)

我也有同样的问题。 GIDSignInButton对象不需要代码中的addTarget或链接@IBActionGIDSignInButton类已经为我们处理了该操作。

答案 2 :(得分:0)

Appdelegate中,尝试使用以下代码

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {

    let result = GIDSignIn.sharedInstance().handle(url,
                                                    sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                                                    annotation: options[UIApplication.OpenURLOptionsKey.annotation])
    return result

}