Where did configuration argument go from GIDSignIn method?

3.3k Views Asked by At

I was rebuilding pet IOS project with google and facebook authorization. Google flow used to be like:

GIDSignIn.sharedInstance.signIn(with: config, presenting: presentingViewController) {

        user, error in ///bla bla bla }

But when the GoogleSignIn package was redownloaded, xcode started showing an error. And google authorization flow changed to

GIDSignIn.sharedInstance.signIn(withPresenting: presentingViewController) {

            user, error in ///bla bla bla }

The problem is when I'm doing auth in this "new" way my app crashes with message

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No active configuration.  Make sure GIDClientID is set in Info.plist.'

Also there is no information in google documentation and in github rep. Please help!

3

There are 3 best solutions below

0
Abdullah On BEST ANSWER

The function updated and with: config parameter removed. Client_ID value from googleservice-info should be added info.plist as GIDClientID key. your function should be

func googleSign(){
  
    
    guard let presentingVC = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first?.rootViewController else {return}
    // Start the sign in flow!
    GIDSignIn.sharedInstance.signIn(withPresenting: presentingVC) { user, error in
        if let error = error {
            print(error.localizedDescription)
            return
          }

          guard let authentication = user?.authentication, let idToken = authentication.idToken
          else {
            return
          }

          let credential = GoogleAuthProvider.credential(withIDToken: idToken,
                                                         accessToken: authentication.accessToken)
        self.showCustomAlertLoading = true
        Auth.auth().signIn(with: credential) { authResult, error in
            guard let user = authResult?.user, error == nil else {
                self.signUpResultText = error?.localizedDescription ?? "Error Occured"
                DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
                    self.showCustomAlertLoading = false
                })
                return}
            self.signUpResultText = "\(user.email!)\nSigning Succesfully"
            self.isSignUpSucces = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: {
                self.showCustomAlertLoading = false
                DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
                    self.navigateHome = true
                })
            })
            print("\(user.email!) signed****")
            
        }
    }
}
0
Nico Cobelo On

Make sure you are downloading version 6.0.2 in order to get GIDSignIn.sharedInstance.signIn(with: presenting: callback)

0
devPau On

I wouldn't suggest adding CLIENT_ID to your Info.plist. According to the Firebase official documentation, they recommend obtaining it directly from the GoogleService-Info file.

Imagine a scenario where you have multiple Firebase projects, each with a different GoogleService-Info for staging, testing, production, all in the same project. In that case, you will likely encounter errors, or you will have to change your Info.plist for each build, depending on the environment, as each file has its own CLIENT_ID.

You should just use:

guard let clientID = FirebaseApp.app()?.options.clientID else { return }
let config = GIDConfiguration(clientID: clientID)

GIDSignIn.sharedInstance.configuration = config

GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { [unowned self] signInResult, error in
   // bla, bla, bla
}

https://firebase.google.com/docs/auth/ios/google-signin