0

I am working in project which have google signin feature in the application. The app works fine in all the iOS except iOS9 and above.

below are the code i used for google signin:-

-(void)methodcallwhenclick_ongoogleSigninbutton{
      GIDSignIn *signInInstance = [GIDSignIn sharedInstance];
        signInInstance.delegate = self;
        GIDSignIn *signIn = [GIDSignIn sharedInstance];
        [signIn signOut];
        signIn.shouldFetchBasicProfile = YES;
        signIn.delegate = self;
        signIn.uiDelegate = self;
        [signIn setClientID:@"<Clientkey>.apps.googleusercontent.com"];
        [signIn setScopes:[NSArray arrayWithObject:@"https://www.googleapis.com/auth/plus.login"]];
        [signIn setDelegate: self];
        [signIn signIn];
}

This method called when i successfully signin into the application but in ios9 this method is not getting called.The google signin view open in the webview and after i click "ALLOW" the webview get dismiss. I am not able to get the authcode of the google in ios9.Is there any way to call this method in ios9 and above version

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error
{

}
Developer
  • 287
  • 1
  • 3
  • 12
  • Are you following the new Google SignIn guides https://developers.google.com/identity/sign-in/ios/start? – ajmccall Nov 26 '15 at 15:55

2 Answers2

6

I faced the same issue: google sign in via GIDSignIn works perfectly for

But for iOS9, Google.com page is opened once allow is pressed. If I press Done button on this page, control enters into aformentioned method, with error = Error Domain=com.google.GIDSignIn Code=-5 "The user canceled the sign-in flow." UserInfo={NSLocalizedDescription=The user canceled the sign-in flow.}

I researched a bit. Found two possible solution:

  1. Whitelist signin related urls- Google Sign-In crashes on iOS 9 attempting to call canOpenURL

  2. Use handleurl call- GIDSignIn iOS 9

Not getting time to test which suits best. Will update as soon as final solution is here.

Update: Did it!!

iOS9 has updated handleUrl() call. Streamlined two approaches as follows:

(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options NS_AVAILABLE_IOS(9_0)
{
    return [self application:app
        processOpenURLAction:url
          sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                  annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
                  iosVersion:9];
}


(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [self application:application
        processOpenURLAction:url
          sourceApplication:sourceApplication
                  annotation:annotation
                  iosVersion:8];
}

(BOOL)application:(UIApplication *)application processOpenURLAction:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation iosVersion:(int)version
{
    return [[GIDSignIn sharedInstance] handleURL:url
                               sourceApplication:sourceApplication
                                      annotation:annotation];
}
Community
  • 1
  • 1
Apporve Chandra
  • 291
  • 3
  • 11
1

This worked for me. I was experiencing object of GIDGoogleUser was becoming nil. The error was 'The user canceled the sign-in flow'. Correct type casting for this is to use as!. This removed the safari hanging after clicked on 'Done'.

On AppDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

        let result = GIDSignIn.sharedInstance().handle(url,
                //added exclamation mark
                sourceApplication: String(describing: options[UIApplicationOpenURLOptionsKey.sourceApplication]!),
                annotation: options[UIApplicationOpenURLOptionsKey.annotation])

        return result

    }
Alvin George
  • 14,148
  • 92
  • 64