没有Google+按钮的trySilentAuthentication(trySilentAuthentication without Google+ button)

编程入门 行业动态 更新时间:2024-10-24 06:32:55
没有Google+按钮的trySilentAuthentication(trySilentAuthentication without Google+ button)

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

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]方法不会在每次用户登录时都离开,但如果不使用google +按钮GPPSignInButton则无法使用

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

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? 提前致谢

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];

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];

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

最满意答案

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

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

编辑:澄清trySilentAuthentication的用途。

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

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

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

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.

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].

EDIT: To clarify what trySilentAuthentication is for.

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).

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.

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.

更多推荐

本文发布于:2023-07-27 17:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   Google   button   trySilentAuthentication

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!