GIDSignIn.sharedInstance()。currentUser当重新启动应用程序时为零
最初,我在检查问题时发现问题,看看我们是否已将数据保存到钥匙串中。我发现这个职位,并随后BhavinBhadani建议:GIDSignIn.sharedInstance()。currentUser当重新启动应用程序时为零
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的用户成功登录之前后再已造成应用程序并重新运行。即使这样做后
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
为零。
是否有人成功使用signInSilently()
来再次填充当前用户数据?
我提出这问题git的一个点,你还需要检查hasAuthInKeychain
这样之前添加范围。这对我的作品,希望同样的话
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");
}
make sure after
GIDSignIn.sharedInstance().signInSilently()
, there is some delay to callgetApplicationData(dataApi)
to populate data.
您是否尝试过在删除应用程序之后。它可能在登录时没有将钥匙串共享功能添加到应用程序。现在当你试图获得
if GIDSignIn.sharedInstance().hasAuthInKeychain()
它返回true,但当前用户仍然为零。
我遇到了同样的问题,所以删除了应用程序并重新登录。现在我可以看到当前用户。
这不是很快 –
我已经编辑了答案,以包含帖子中的代码。问题中提到的问题是关于当前用户为零。我还写道:'这已经解决了我的第一个GIDSignIn.sharedInstance()问题。hasAuthInKeychain()在用户成功登录之后返回true,然后杀死了应用并重新运行。'。我还问:'有没有人成功使用过signInSilently()来再次填充当前用户数据?' – pls
@pls是否会在崩溃时提供任何日志? –