2014-07-21 41 views
0

我新的iOS开发/ Objective C的,所以请温柔;-)储存谷歌应用程序的权限 - iOS设备

我创建一个使用Google+登录SDK的应用程序,我有一个工作原型,其中用户点击谷歌登录按钮,然后他们被重定向到safari,他们登录到他们的Google帐户,并最终在我的应用程序中出现帐户权限屏幕,然后返回到iOS应用程序。

我遇到的问题是,在允许应用程序访问相关信息后,当用户通过Google登录登录到应用程序时,用户会不断导航到账户权限屏幕。

现在,我的印象是,一旦用户允许该应用访问相关信息,那么用户将不会被要求批准这一点,除非他们通过security.google.com撤销了访问权限,但我发现每次登录尝试后,我总是需要批准权限。

有没有人有过这个问题?我已经执行了一些谷歌搜索来寻找这个问题的答案,但没有多少运气。任何帮助将非常感激!

谢谢。下面

代码:

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    GPPSignIn *signIn = [GPPSignIn sharedInstance]; 
    signIn.shouldFetchGooglePlusUser = YES; // get the user profile 
    signIn.shouldFetchGoogleUserEmail = YES; // get the user's email 
    signIn.scopes = @[ @"profile" ];   // "profile" scope 

    // Optional: declare signIn.actions, see "app activities" 
    signIn.delegate = self; 

    [signIn trySilentAuthentication]; 

} 

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { 

     GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"]; 

     // 1. Create a |GTLServicePlus| instance to send a request to Google+. 
     GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ; 
     plusService.retryEnabled = YES; 

     // 2. Set a valid |GTMOAuth2Authentication| object as the authorizer. 
     [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication]; 

     // 3. Use the "v1" version of the Google+ API.* 
     plusService.apiVersion = @"v1"; 
     [plusService executeQuery:query 
       completionHandler:^(GTLServiceTicket *ticket, 
            GTLPlusPerson *person, 
            NSError *error) 
     { 

      if (error) { 

       NSLog(@"Received Error %@ and auth object==%@", error, auth); 

      } 

      else { 
       // Send the basic user information to the console 
       NSLog(@"Email=%@", [GPPSignIn sharedInstance].authentication.userEmail); 
       NSLog(@"User Name=%@", [person.name.givenName stringByAppendingFormat:@" %@", person.name.familyName]); 
[self performSegueWithIdentifier:@"loginSuccessful" sender:self]; // Once logged in send user to main view 
} 

回答

0

我认为你正在寻找trySilentAuthentication这是在SDK中的谷歌标志的一部分。你可以在这里找出谁使用它:http://developers.google.com/+/mobile/ios/sign-in

+0

嘿,谢谢你的快速反应。我在登录视图控制器的viewDidLoad方法中使用这个,除非这是不正确的地方? –

+0

没有,这是正确的地方。你能分享你的代码吗? – Mika

+0

好的,我已经添加了处理登录功能的两个方法的代码。 –

相关问题