35

In Xcode settings's Info tab for project (not target's Info tab), I have 3 different build configurations, each with 2 .xcconfig files set up for my iOS Xcode project. enter image description here

I want to have different bundle identifiers for different configurations for better code signing management. Below are my general identity settings, info tab settings and bundle identifier settings under build settings.

enter image description here

INFO section-

enter image description here

BUILD SETTINGS-

enter image description here

When I update the bundle identifier directly in general section, the value in build settings --> Product Bundle Identifier gets overridden for all the build configurations.

Please suggest me a better way to manage this!!

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Rashmi Ranjan mallick
  • 6,390
  • 8
  • 42
  • 59

2 Answers2

27

As far as I can see, you have already set up individual xcconfig files for each configuration. That means you can just add the bundle identifier key with the corresponding value to each build configuration / xcconfig file.

PRODUCT_BUNDLE_IDENTIFIER = com.mycomp.hockey

You need to make sure that you do not override these xcconfig settings in your Xcode project build settings (the corresponding value should not be bold).

If you want to switch between your bundle identifiers on the fly you might want to create one scheme per build configuration. That way you can just select the corresponding scheme in the Xcode scheme selector (next to the build/run button).

enter image description here

To create a new scheme, just select New scheme from the scheme selector and choose a name, e.g., MyApp [Hockey]. Then edit the scheme and select the preferred build configuration for each step, e.g., MyApp [Hockey] for the Archive step.

enter image description here

You will notice that the bundle identifier on your target info screen will change depending on the selected scheme. Sometimes you need to switch to a different tab of your project settings and then back to the Info tab before the bundle identifier changes (one of many Xcode bugs).

We use the exact same approach for all our projects.

Hope that helps.

shim
  • 9,289
  • 12
  • 69
  • 108
Jens Meder
  • 4,237
  • 1
  • 25
  • 25
  • @JensMeder- Thanks for your answer. I am not using separate xconfig file yet. But sounds like a good approach. I'll give this a try. One doubt- when you have separate xconfig file for each scheme, what value do you specify in the general section --> bundle Identifier field? – Rashmi Ranjan mallick Oct 18 '16 at 19:00
  • Short answer: nothing ;-). Long Answer: What you see in the Bundle Identifier field on the General tab is actually the value from your build settings. Whenever you change the value in your build settings or an xcconfig file the value on the General tab will change as well. You can try it yourself by changing the bundle identifier value in your build settings and you will see that the General value changes to this new value as well. – Jens Meder Oct 19 '16 at 08:11
  • Thanks!! If you see the screenshots in my question, I have different values for Product Bundle Identifier for different build configurations. But, the first value (i.e. com.mycomp.xyz) gets populated in general section. Is it fine? – Rashmi Ranjan mallick Oct 19 '16 at 10:25
  • If you follow the aforementioned approach with different xcconfig files and schemes then the value in the General tab depends on the selected scheme and the selected build configuration of the `Run` step in that scheme. – Jens Meder Oct 19 '16 at 10:41
  • Ohh okay!! That sounds better now. – Rashmi Ranjan mallick Oct 19 '16 at 10:44
  • You said that it takes the selected build configuration from "Run" step. So, the value specified in "Archive" step won't impact? – Rashmi Ranjan mallick Oct 19 '16 at 10:46
  • Anyway, I will give a try for this xconfig method. – Rashmi Ranjan mallick Oct 19 '16 at 10:46
  • Well, the archive step will impact as well, but only if you choose "Archive" to create an app bundle for deployment via Product->Archive. There will not be any visual changes to the General tab. Xcode will pick the corresponding bundle identifier depending on what you want to do, e.g., Profile, Run, Archive, etc. . Therefore, I suggest to choose the same build configuration for each of the steps for a given scheme. Hope that helps. – Jens Meder Oct 19 '16 at 12:32
  • Ok!! Thanks for all your valuable inputs – Rashmi Ranjan mallick Oct 19 '16 at 15:39
  • Is there a way maintain different `Version` and `Build` string for each bundle identifier? – arjun May 09 '18 at 09:29
  • Bundle identifier on your target info is not getting updated depending on the selected scheme. I tried changing tabs as well. It is showing info of One scheme only irrespective of currently selected scheme. – Gaurav Borole Mar 18 '19 at 08:18
  • Don't forget to replace your set of bundle id in project.pbxproj to PRODUCT_BUNDLE_IDENTIFIER = "$(PRODUCT_BUNDLE_IDENTIFIER)"; – Pavel Shorokhov Apr 17 '20 at 22:36
25

Jens' answer was a bit confusing to me. All you have to do is add the xcconfig declared variable (PRODUCT_BUNDLE_IDENTIFIER = com.mycomp.hockey) to the Info.plist product bundle identifier field:

Info.plist variable example

Also don't forget to declare it in every xcconfig file. Enjoy.

David
  • 2,109
  • 1
  • 22
  • 27