GPPSignIn delegate methods fail?

I enabled Goolge + signin in iOS (using ObjC) following the instructions on google website, but delegate methods (I'm interested in this finishedWithAuth:auth:error method) GPPSignIn not executed, I need to save the access token received in the delegate method, in general settings.

Here is my code:

`

 -(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { NSLog(@"Received error %@ and auth object %@",error, auth); if (error) { NSLog(@"error"); } else { NSLog(@"success"); } } - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { NSLog(@"application"); return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; } -(void)refreshInterfaceBasedOnSignIn { NSLog(@"refreshInterfaceBasedOnSignIn"); if ([[GPPSignIn sharedInstance] authentication]) { // The user is signed in. self.signInButton.hidden = YES; [self readProfileInformation]; // Perform other actions here, such as showing a sign-out button [self readProfileInformation]; NSLog(@"readProfileInformation"); } else { self.signInButton.hidden = NO; // Perform other actions here } } - (void)disconnect { [[GPPSignIn sharedInstance] disconnect]; } - (void)didDisconnectWithError:(NSError *)error { if (error) { NSLog(@"Received error %@", error); } else { // The user is signed out and disconnected. // Clean up user data as specified by the Google+ terms. } } - (void)signOut { [[GPPSignIn sharedInstance] signOut]; } -(void)viewDidLoad { [super viewDidLoad]; // google+ code GPPSignIn *signIn = [GPPSignIn sharedInstance]; signIn.shouldFetchGooglePlusUser = YES; // uncommented to fetch user email signIn.shouldFetchGoogleUserEmail = YES; // You previously set kClientId in the "Initialize the Google+ client" step signIn.clientID = kClientId; // Uncomment one of these two statements for the scope you chose in the previous step // signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // uncommented & set to "profile" & "email" scope: signIn.scopes = @[ @"profile", @"email" ]; // Optional: declare signIn.actions, see "app activities" signIn.delegate = self; // try silent authentication [signIn trySilentAuthentication]; } @end 

`

thanks

+5
source share
1 answer

This happened to me in my applications running iOS 8. That I needed to set the clientId in AppDelegate right after launching the application, and not in the viewDidLoad method of my UIViewController class, as indicated in Google+ Sign in for iOS example at the following URL: https : //developers.google.com/+/mobile/ios/sign-in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { / //Google+ // Set app client ID for |GPPSignIn| and |GPPShare|. [GPPSignIn sharedInstance].clientID = @"xxxxxx.......apps.googleusercontent.com"; ... return YES; } 

So, in your UIViewController class, the login method should be:

  - (void)viewDidLoad { [super viewDidLoad]; //Google+ for Logging in the user again if the app has been authorized signIn = [GPPSignIn sharedInstance]; signIn.shouldFetchGooglePlusUser = YES; signIn.shouldFetchGoogleUserID = YES; signIn.shouldFetchGoogleUserEmail = YES; signIn.scopes = @[ kGTLAuthScopePlusLogin ]; signIn.delegate = self; [signIn trySilentAuthentication]; ... } 
+4
source

Source: https://habr.com/ru/post/1213213/


All Articles