没有Google+按钮的trySilentAuthentication [英] trySilentAuthentication without Google+ button

查看:101
本文介绍了没有Google+按钮的trySilentAuthentication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS中实施Google+登录,我使用此代码并且工作正常

I am implementing Google+ sign in in iOS , I used this code and it works fine

signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
//signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin,nil];
signIn.actions = [NSArray arrayWithObjects:@"http://schemas.google.com/ListenActivity",nil];
[signIn authenticate];

我想使用[signIn trySilentAuthentication]方法,每次用户登录时都不会离开没有使用谷歌+按钮GPPSignInButton

I want to use [signIn trySilentAuthentication] method to doesn't leave up each time user log in but it doesn't work without using google+ button GPPSignInButton

所以,使用此代码而不是上面的代码有什么问题

So , what wrong with using this code instead of the one above

  signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
//signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin,nil];
signIn.actions = [NSArray arrayWithObjects:@"http://schemas.google.com/ListenActivity",nil];
[signIn trySilentAuthentication];

是否可以在didSelectRowAtIndexPath中使用trySilentAuthentication?
提前谢谢

Is it possible to use trySilentAuthentication with didSelectRowAtIndexPath ? thanks in advance

推荐答案

是的,当然。确保您正在调用[[GPPSignIn sharedInstance] trySilentAuthentication]并且不创建新的GPPSignIn实例,并确保在设置GPPSignIn实例后仅将其命名为

Yep, for sure. Make sure you are calling [[GPPSignIn sharedInstance] trySilentAuthentication] and not creating a new GPPSignIn instance, and make sure you only call it after you have set up the GPPSignIn instance.

所以你需要将你的片段分成两部分:在一些早期方法(viewWillAppear或甚至在app委托中)中设置sharedInstance上的参数,并调用trySilentAuthentication。当您从didSelectRowAtIndexPath接收调用时,请调用[[GPPSignIn] sharedInstance] authenticate]。

So you would need to split you snippet into two: in some early method (viewWillAppear or even in the app delegate) set the parameters on the sharedInstance, and call trySilentAuthentication. When you get the call from didSelectRowAtIndexPath, then call [[GPPSignIn] sharedInstance] authenticate].

编辑:澄清trySilentAuthentication的用途。

To clarify what trySilentAuthentication is for.

当您致电身份验证时,系统会将用户带到Google+应用,Chrome或Safari进行登录。当他们回来时,会将长期存在的令牌存储在用户的钥匙串,以及用于进行API调用的短期令牌。调用trySilentAuthentication检查长期存在的令牌是否在密钥链中,并生成一个新的短期令牌。如果成功,则意味着用户之前已在该设备上登录该应用程序,因此您通常希望对此进行适当的响应。如果它失败(没有令牌)它将只返回false,或者如果它不能生成一个短期令牌,它将调用finishedWithAuth:error并设置错误。它永远不会将用户带到另一个应用程序进行身份验证(因此是静默部分)。

When you call authenticate, the user is taken out to Google+ app, Chrome, or Safari to sign in. When they come back, a long lived token is stored in the keychain for the user, as well as a short lived token for making API calls. Calling trySilentAuthentication checks whether the long lived token is in the key chain, and generates a new short lived token. If it succeeds it means the user has signed in to that app on that device before, so you generally will want to respond to that appropriately. If it fails (there is no token) it will just return false, or if it can't generate a short lived token it will call finishedWithAuth:error with the error set. It will never take the user out to another app to authenticate (hence the silent part).

您通常希望在流程中尽早调用trySilentAuthentication以便了解用户的状态。这并不意味着您无法向其提供其他登录选项。

You generally want to call trySilentAuthentication very early in the flow in order to learn the state of the user. That does not mean you can't present other sign-in options to them.

在您的情况下,似乎如果应用重启,您想要向他们显示登录屏幕。如果对用户来说有点不愉快,那很好。您可以做的是尽早运行trySilentAuthentication,但是在finishedWithAuth:错误中,而不是立即切换到下一个屏幕,只需存储auth对象。然后,当用户按下表格中的Google+条目时,请转到该点的下一个视图。

In your case it seems like that if the app restarts you want to show the sign in screen to them. That's fine, if a little unpleasant for the user. What you can do is run trySilentAuthentication early on, but in the finishedWithAuth:error, instead of immediately switching to the next screen, just store the auth object. Then when the user presses the Google+ entry in the table, flip to the next view at that point.

这篇关于没有Google+按钮的trySilentAuthentication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆