Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS swift You must specify clientID Exception in google integration

Tags:

ios

swift

Code:

let signIn = GPPSignIn.sharedInstance()
        signIn.shouldFetchGooglePlusUser = true
        signIn.clientID = "912597493260-qg351fl8olmnmjl8qobos8n6u909jp0o.apps.googleusercontent.com"
        signIn.scopes = [kGTLAuthScopePlusLogin];
        signIn.trySilentAuthentication();
        GIDSignIn.sharedInstance().signInSilently()
        signIn.delegate = self

due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|

I double checked my code.Even i set client-id getting this exception.Where i went wrong?any help will be appreciated.thanks in advance

like image 293
aavind aravind Avatar asked Jul 28 '16 16:07

aavind aravind


1 Answers

I was following Google's own guide for adding Sign-In here. I followed it step by step - integrated the google configuration file too. As per the guide, if the configuration file was included, setting the client id manually was not required. Unfortunately, I encountered exactly the same error when I run the app and hit the Sign-In button:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|'

Solution:

For some reason, clientID was not automatically picked from the configuration file. We should instead configure the GIDSignIn object directly, (using the client ID found in the GoogleService-Info.plist file) in the app delegate's application:didFinishLaunchingWithOptions: method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      // Initialize sign-in
      var configureError: NSError?
      GGLContext.sharedInstance().configureWithError(&configureError)
      assert(configureError == nil, "Error configuring Google services: \(configureError)")
      GIDSignIn.sharedInstance().clientID = "Cliend id From GoogleService-Info.plist file"
      GIDSignIn.sharedInstance().delegate = self
      return true
}

Also, if you are using Firebase, you can do it this way too:

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
like image 118
Mohit Singh Avatar answered Oct 21 '22 04:10

Mohit Singh