2

I am integrating GCM in an app and we happen to have several build configurations for the same target and some of them use different Bundle Ids (we have different accounts, enterprise and appstore) so if we want to enable GCM push notifications in both we need two different GoogleService-Info.plist files (each one for the different BundleID). I cannot find a way to tell the GCM sdk to initialize from a different named file but the default one. Does anyone know if this is possible?

I can think of a two solutions, but I would rather not do them. - Write to the plist file the bundle id once the app is started (or before) - Create a different Target each one with a different plist file

Thanks a lot.

Regards, Javier

javierdfm
  • 359
  • 1
  • 4
  • 10
  • You are right that you need to have two different `GoogleService-Info.plist` files for Enterprise and Appstore accounts. But I don't think it is possible to have two or more GoogleService-Info.plist in one target. It is better to *"create a different Target each one with a different plist file"* as you have stated. So, if the target is enterprise, use one .plist file, if the other target is the release version, use another plist file. Check this related [question](http://stackoverflow.com/questions/28414957/xcode-picks-up-wrong-info-plist-file-when-generating-the-app-file). – abielita Apr 05 '16 at 07:48
  • 1
    Thanks, I've decided that In the end I will edit the GoogleService-Info.plist file on a Run Script Build Phase to set the correct value for the bundle identifier. – javierdfm Apr 05 '16 at 13:00
  • did the run script in the build phase work? I see that as the only option, but cant seem to get my script to work. Can you share yours as the answer? – Nitin Alabur Sep 14 '16 at 19:14

1 Answers1

3

I had a similar problem: Use User-Defined build settings in custom .plist file

You can use a Build Phase Script to copy the proper .plist file to your location:

  1. Create a new folder (for example: GoogleServiceInfoPlists).
  2. Copy there all .plist files (for example: GoogleService-Info-Debug.plist, GoogleService-Info-Stage.plist and GoogleService-Info-Prod.plist).
  3. Add new Run Script Phase (Xcode: Target->Build Phases->"+" button)
  4. Use script below to copy (replace) .plist file for given environment to the main directory (it's src in my case):

    cp "${SRCROOT}/src/Resources/GoogleServiceInfoPlists/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/src/GoogleService-Info.plist"
    

Please note that src/GoogleService-Info.plist file must be added to the Xcode project (Build Phases->Copy Bundle Resources) while /src/Resources/GoogleServiceInfoPlists/GoogleService-Info-* files not necessarily.

KlimczakM
  • 12,576
  • 11
  • 64
  • 83