我正在将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
更改按钮,它可以工作,但是样式丢失。
答案 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
或链接@IBAction
。 GIDSignInButton
类已经为我们处理了该操作。
答案 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
}