重新启动应用程序时,GIDSignIn.sharedInstance().currentUser为零 [英] GIDSignIn.sharedInstance().currentUser nil when relaunching app
问题描述
最初,我在检查是否存在问题,以查看是否已将数据保存到钥匙串中.我找到了这篇文章,并遵循了BhavinBhadani的建议:
Initially I was having a problem with the check to see if we have saved data into the keychain. I found this post and followed the suggestion by BhavinBhadani:
无论何时检查([GIDSignIn sharedInstance] .hasAuthInKeychain), 在此之前,请先添加您的登录范围.
Whenever you check if ([GIDSignIn sharedInstance].hasAuthInKeychain) , before that add your sign in scopes..
https://github.com/googlesamples/google-services/issues/27
这解决了我的第一个问题,即GIDSignIn.sharedInstance().hasAuthInKeychain()
在用户之前成功登录然后终止应用程序并重新运行之后返回true.
This has solved my first problem of GIDSignIn.sharedInstance().hasAuthInKeychain()
returning true after the user has logged in successfully before and then has killed app and re runs.
但是现在我正在执行以下操作:
However now I am doing the following:
let signIn = GIDSignIn.sharedInstance()
signIn.scopes = [Constants.GOOGLE_CLIENT_SCOPE, Constants.GOOGLE_OIDC_SCOPE]
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
print("We have saved in keychain")
if let u = GIDSignIn.sharedInstance().currentUser {
getData(dataApi)
}
else {
// THIS CODE IS BEING SUCCESSFULLY HIT
GIDSignIn.sharedInstance().signInSilently()
getApplicationData(dataApi)
}
}
但是即使这样做:GIDSignIn.sharedInstance().signInSilently()
GIDSignIn.sharedInstance().currentUser
也为零.
However even after doing: GIDSignIn.sharedInstance().signInSilently()
the GIDSignIn.sharedInstance().currentUser
is nil.
有人成功使用signInSilently()
再次填充了currentUser数据吗?
Has anyone successfully used signInSilently()
to populate the currentUser data again?
推荐答案
我在git中指出该问题,您还需要在像这样检查hasAuthInKeychain
之前添加作用域.你
I make a point in that issue in git that you also need to add scopes before check hasAuthInKeychain
like this .. this works for me and hope same for you
let signIn = GIDSignIn.sharedInstance()
signIn.scopes = ["https://www.googleapis.com/auth/plus.login","https://www.googleapis.com/auth/plus.me"]
if (signin.hasAuthInKeychain) {
print("Signed in");
} else {
print("Not signed in");
}
确保在
GIDSignIn.sharedInstance().signInSilently()
之后,调用getApplicationData(dataApi)
填充数据会有一些延迟.
make sure after
GIDSignIn.sharedInstance().signInSilently()
, there is some delay to callgetApplicationData(dataApi)
to populate data.
这篇关于重新启动应用程序时,GIDSignIn.sharedInstance().currentUser为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!