我一直在尝试在他们的Objective-C库中使用谷歌提供的OAuth2 api。
无论如何,我在理解如何让应用程序记住谁登录时遇到了麻烦。我已经使用下面的代码成功地完成了身份验证。
我调用下面的方法来呈现来自谷歌的OAuth视图控制器,用户登录,然后我就通过了身份验证。然而,每次我重新启动应用程序时,它都会再次运行登录屏幕,就好像我没有通过身份验证一样。据我所知,我需要有某种类型的密钥链/令牌记忆,以便它能够识别最近登录的用户。
但是怎么做呢?我不能通过一些可用的文档来解决这个问题。
-(void)authenticateUserFromViewController:(UIViewController *)viewController
{
GTMOAuth2ViewControllerTouch *authViewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeYouTube
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[viewController.navigationController pushViewController:authViewController animated:YES];
}
-(void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
if (error != nil)
{
// Authentication failed
NSLog(@"Failed to authorise");
}
else
{
// Authentication succeeded
NSLog(@"Authorised");
}
}发布于 2013-07-16 02:33:19
我不熟悉Objective-C库,但也许this part of the Google Reference会很有用。它解释了如何使用身份验证令牌,以及如何在用户重新启动应用程序时处理密钥链。
https://stackoverflow.com/questions/17642258
复制相似问题