2
votes

I've followed the tutorial for Google Sign-In Swift and have the button showing, and am successfully redirected to log into an account. However, I want to segue to another view after a successful signin and the delegate function "didSignInFor" isn't being called. I've placed breakpoints at "didSignInFor" and "signIn Dispatch error" but none of them are being called.

Does anyone know what's wrong or what else I can check to figure out what's going wrong?

import UIKit
import GoogleSignIn
import FacebookLogin

class LoginViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {

override func viewDidLoad() { super.viewDidLoad() var error: NSError? GIDSignIn.sharedInstance().uiDelegate = self GIDSignIn.sharedInstance().delegate = self } func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if let error = error { print("\(error.localizedDescription)") } else { // Perform any operations on signed in user here. let userId = user.userID // For client-side use only! let idToken = user.authentication.idToken // Safe to send to the server performSegue(withIdentifier: "LoginToDashboard", sender: self) } } func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) { print(error) }

}

This is similar to this question but has not been answer: google signin not calling delegate method after success

1
Did you check if you have any other class in your project that implements GIDSignInDelegate? Maybe the delegate gets set to something else. - Julien Perrenoud
Also which authentication method are you using when you test? In-app controller, safari? Did you test all the potential answers from the thread you linked? - Julien Perrenoud
I figured out my problem. It was extremely silly, I didn't set the viewController's class to my LoginViewController... - Vivian

1 Answers

1
votes

The Google sign-in guide that you linked says that AppDelegate should conform to GIDSignInDelegate (and so implement didSignInFor) while the ViewController that contains the sign-in button should conform to GIDSignInUIDelegate. I'd try to stick to the guide and see if it solves the problem.