Search code examples
iosobjective-cgoogle-signinxcode7.2ios9.2.1

Google Login Issue in OS 9.2 Xcode 7.2


I am using Xcode 7.2, testing on iOS 9.2 and using pod 'Google/SignIn'

After login success and allowing the permission its redirect to the google.co.in page instead of close the screen and calling their delgates. The same is working fine in OS 7.0 and 8.0. Below is the code used for login.

GIDSignIn*sigNIn=[GIDSignIn sharedInstance];
[sigNIn setDelegate:self];
[sigNIn setUiDelegate:self];
sigNIn.shouldFetchBasicProfile = YES;
sigNIn.allowsSignInWithBrowser = NO;
sigNIn.allowsSignInWithWebView = YES;
sigNIn.scopes = @[@"https://www.googleapis.com/auth/plus.login",@"https://www.googleapis.com/auth/userinfo.email",@"https://www.googleapis.com/auth/userinfo.profile"];
sigNIn.clientID =@"77904325793-iqdungs3ugddrf7h767pgagviokfi4cg.apps.googleusercontent.com";
[sigNIn signIn];



 - (BOOL)application:(UIApplication *)app
        openURL:(NSURL *)url
        options:(NSDictionary *)options {
return [[GIDSignIn sharedInstance] handleURL:url
                           sourceApplication:options[UIApplicationLaunchOptionsSourceApplicationKey]
                                  annotation:options[UIApplicationLaunchOptionsAnnotationKey]];


}

After login it redirect to google.co.in instead of close the screen.

enter image description here


Solution

  • I guess, it is because the openUrl function has been changed in iOS 9.

    To solve such a problem, annotate the functions according to the iOS version available.

    Here is what I did to solve it:

    @available(iOS 9.0, *)
    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    
        return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey]! as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    }
    
    @available(iOS 8.0, *)
    func application(application: UIApplication,
        openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    
        return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation)
    }
    

    Let me know if this solved your problem.