Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIDSignIn Type of expression is ambiguous without more context

I've been following this tutorial here for adding google sign in to my iOS app:https://www.youtube.com/watch?v=TfYIH_23c6w&t=353s

and everything looks good except for this line here:

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

The error is Type of expression is ambiguous without more context

in this file:

//
//  LoginVM.swift
//  frcscout
//
//  Created by Elliot Scher on 12/14/22.
//

import Foundation
import Firebase
import GoogleSignIn

class SignUpViewModel: ObservableObject {
    
    @Published var isLogin: Bool = false
    
    func signInWithGoogle() {
                
        guard let clientId = FirebaseApp.app()?.options.clientID else { return }
        
        let config = GIDConfiguration(clientID: clientId)
        
        GIDSignIn.sharedInstance.signIn(with: config, presenting:ApplicationUtility.rootViewController) {
            [self] user, err in
            
            if let error = err {
                print(error.localizedDescription)
                return
            }
            
            guard
                let authentication = user.authentication,
                let idToken = authentication.idToken
            else { return }
            
            let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)
            
            Auth.auth().signIn(with: credential) { result, error in
                if let error = err {
                    print(error.localizedDescription)
                    return
                }
                
                guard let user = result?.user else { return }
                print(user.displayName)
                isLogin.toggle()
            }
                    
        }
        
    }
}

I'm not sure what this error means. How can I fix it? Thanks!!


1 Answers

1/ Config info.plist

<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
    </array>
  </dict>
</array>

https://developers.google.com/identity/sign-in/ios/start-integrating#add_client_id

2/ Download new GoogleService-Info.plist from firebase

3/ use below function

@objc func signInWithGooglePressed(sender: Any) {

    // Start the sign in flow!
    GIDSignIn.sharedInstance.signIn(withPresenting: self) { signInResult, err in

        if let error = err {
            print(error)
            return
        }

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

        let emailAddress = user?.profile?.email

        let fullName = user?.profile?.name
        let givenName = user?.profile?.givenName
        let familyName = user?.profile?.familyName

        let credential = GoogleAuthProvider.credential(withIDToken: idToken,
                                                     accessToken: authentication.accessToken.tokenString)

        FirebaseProvider.Instance.firebaseGoogleLogin(credential: credential)
    }
    
    
}
like image 179
Trương Quang ân Avatar answered Nov 21 '25 07:11

Trương Quang ân