0

I am working on iOS app which should use API from our website. In order to connect to it user should Log In to his google account from device and then we automatically connect to API. We use https://developers.google.com/identity/sign-in/ios/start-integrating for authorization

The problem is that there is more than one website and each of them has different Client ID.

I've tried to change .plist which stores CLIENT_ID programmatically and it wouldn't work:

@IBAction func signInButtonClicked(sender: AnyObject) {
    let signInPlistDirectory = *pathToGoogleService-Info.plist*
    let signInPlist = NSMutableDictionary(contentsOfFile: signInPlistDirectory)!
    if ((webNodeUrl.text?.hasSuffix(".testing-sites.internal")) != nil) {
        signInPlist["CLIENT_ID"] = signInPlist["TESTING_CLIENT_ID"]
    } else {
        signInPlist["CLIENT_ID"] = signInPlist["PROD_CLIENT_ID"]
    }
    signInPlist.writeToFile(signInPlistDirectory, atomically: true)
}

Maybe anybody knows, is it even possible to do?

1 Answers1

0

The documentation says the following:

If you didn't add additional services when you created the configuration file, you don't need to copy it to your project. However, keep the configuration file, because it contains information that you need to set up your Xcode project.

If you aren't using additional services then you should be able to get away without having to bother with the plist (not that i'm sure what you are doing with the example in your question).

Prior to presenting the login form, you could try something like the following:

let manager = GIDSignIn.sharedInstance()
manager.clientId = "CLIENT_ID_YOU_WANT_TO_USE"
manager.delegate = self
manager.uiDelegate = self
manager.shouldFetchBasicProfile = true
manager.scopes = [
    "https://www.googleapis.com/auth/plus.me"
]

manager.signIn()

I haven't tried setting the clientId value to more than one client identifier during the same runtime period and it's not documented as to wether it will work as it's quite a unique use case but it's worth a shot.

Also remember that you must add all the URL schemes to your project at build time and there is no other way.


From your question, you say that you want to use multiple different websites (with different client id's) however in the code example it looks like you just want to switch between a different development environments (prod and testing). If this is the case then I recommend you take a look at this answer. It provides some useful tips on managing multiple environments.

Community
  • 1
  • 1
liamnichols
  • 12,419
  • 2
  • 43
  • 62