Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google sign in not redirect to application after allow

I'm using this tutorial to implement Sign in with google in app.

  1. I installed GoogleSignIn via cocoapods. pod 'GoogleSignIn', '~> 2.4.0'
  2. Added GSignIn-Bridging-Header.h with #import <GoogleSignIn/GoogleSignIn.h> inside.
  3. Create url types: enter image description here

  4. Create a view with GIDSignInButton class

  5. Added code:

    class ViewController: UIViewController, GIDSignInDelegate,    GIDSignInUIDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().clientID = "KEY" 
     }
    
     func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if let err = error {
       print(error)
    }
    else {
       print(GIDSignIn.sharedInstance().currentUser.profile.name)
       print(GIDSignIn.sharedInstance().currentUser.profile.email)
       self.performSegueWithIdentifier("idSegueContent", sender: self)
      }
    }
    
    
    func signIn(signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!, withError error: NSError!) {
    
    }
    }
    
  6. But when i click allow

enter image description here

It redirects me to google.com, not to app.

like image 633
Arti Avatar asked Mar 14 '23 09:03

Arti


1 Answers

I finally fixed this after a day's work. @ayman Ibrahim was basically, right, but I think that the answer is a bit broader. Different versions of Swift/Objective-C and the Google SDK, call different versions of the canOpenURL method in the AppDelegate. I'm not 100% certain about that, and would appreciate confirmation or correction. Here is the version of that method which worked for me. I am using Google's SDK v. 4.0, targeting iOS 9.1, and using Swift 3.0:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    let checkFB = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
    let checkGoogle = GIDSignIn.sharedInstance().handle(url as URL!,sourceApplication: sourceApplication,annotation: annotation)
    return checkGoogle || checkFB
}

I am also using the FBSDK, so ignore that line.

like image 140
dylanthelion Avatar answered Mar 23 '23 15:03

dylanthelion