12

I have integrated the GoogleSinIn API in my project with Swift 4.0. It is working on iOS 11.0 but when I'm testing the same on iOS 10.0 it is opening the Google login page on the Safari browser or the device and after signing successfully it is opening the Google search page.

  1. When I click the GoogleSignIn button shown below it opens the browser shown in next image.

  2. Then I fill up the credentials.

  3. After the successful signed in, It redirects to the Google page instead of the application page.

TheTiger
  • 13,264
  • 3
  • 57
  • 82
Sahil Dhiman
  • 301
  • 3
  • 13

5 Answers5

9

You have to implement this delegate function in your AppDelegate.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
     return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
TheTiger
  • 13,264
  • 3
  • 57
  • 82
sRoy
  • 267
  • 2
  • 5
5

check your GIDSignInUIDelegate, don't forget

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
    self.present(viewController, animated: true, completion: nil)
}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {
    self.dismiss(animated: true, completion: nil)
}
Yifan
  • 1,185
  • 12
  • 18
  • 1
    hi, with this method I am able to google sign in. But after sign in, i want to go to drive file list. It is redirecting me to google.com . Can you help? – Krutika Sonawala Feb 12 '18 at 06:00
2

Google documentation sucks! I'm using iOS 10 and documentation says to add the second method I wrote only if using iOS 8.0 or older. Don't know why. I got success adding these two methods:

// [START openurl]
func application(_ application: UIApplication,
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
}
// [END openurl]
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return GIDSignIn.sharedInstance().handle(url,
  sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
  annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
Edoardo Vicoli
  • 227
  • 2
  • 8
0

I was using wrong handler in AppDelegate.

Previously I was using:

private func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool

But it should be:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
TheTiger
  • 13,264
  • 3
  • 57
  • 82
Sahil Dhiman
  • 301
  • 3
  • 13
0
- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {


    BOOL handleGoogleSignIn = [[GIDSignIn sharedInstance] handleURL:url
                                              sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                         annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
    if (handleGoogleSignIn) {
        return handleGoogleSignIn;
    }
}

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

    BOOL handleGoogleSignIn = [[GIDSignIn sharedInstance] handleURL:url
                           sourceApplication:sourceApplication
                                  annotation:annotation];
    if (handleGoogleSignIn) {
        return handleGoogleSignIn;
    }
}

If you use sourceApplication ,you need write GoogleSignIn return both.

wormlxd
  • 514
  • 3
  • 7