问题描述
使用Google Plus SDK
登录.一开始一切都很好,但是似乎oauth令牌在大约1小时后过期.我正在遵循Google网站上的建议,并使用
Using Google Plus SDK
for sign-in. Everything works great at first, but appears that the oauth token is expiring after about 1 hour. I am following the recommendations on Google's site and using
[signIn trySilentAuthentication]
在viewDidAppear函数中.
in viewDidAppear function.
我知道令牌已过期,因为我正在服务器上使用Oauth并收到401响应.
I know the token is expired because I am using Oauth on my server and getting a 401 response.
还值得注意的是,如果在打开屏幕的情况下将iPhone/iPad插入电源,则这不是问题.在这种情况下,该应用程序可以无限期运行,没有任何问题.
Also worth noting that this is not a problem if the iPhone/iPad is left plugged in with the screen on. In this case the app works indefinitely without any issues.
我的Cloud Endpoint上的身份验证失败.我正在初始化服务,如下所示:
The authentication fails on my Cloud Endpoint. I am initializing the service as below:
static GTLService *service = nil;
if (!service) {
service = [[GTLServiceMyModel alloc] init];
service.retryEnabled = YES;
[service setAuthorizer: [GPPSignIn sharedInstance].authentication];
}
如果该应用程序的令牌已过期,那么我现在要解决的方法是使用iOS应用程序切换器关闭该应用程序,然后再次启动该应用程序.然后,该应用将在令牌过期之前再次运行约一个小时.
Also if the app has an expired token the work around I have right now is to close the app by using the iOS app switcher and launch app again. The app will then work again for about an hour before token expires.
有人遇到过这个问题吗?任何帮助将不胜感激!
Has anyone ran into this issue? Any help would be GREATLY appreciated!
推荐答案
我的问题是我在设置服务的授权者.这个代码块只是在我的方法第一次被调用时才运行.来自Java背景,我对方法中的静态变量一无所知.现在我知道了!!只需将setAuthorizer移到块外,一切正常.
My issue was where I was setting the authorizer for the service. This code block was only getting ran the first time my method was called. Coming from a Java background I was not savvy on static variables in methods. Now I know!! Just moved the setAuthorizer to outside the block and everything works.
static GTLService *service = nil;
if (!service) {
service = [[GTLServiceMyModel alloc] init];
service.retryEnabled = YES;
[service setAuthorizer: [GPPSignIn sharedInstance].authentication];
}
这篇关于Google Plus SDK无法刷新令牌(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!