Search code examples
ios9xcode7google-signin

google signin issue in ios9


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
{

}

Solution

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