0
votes

I am trying to maintain two bundle identifiers for the same app: one for the development state, another for the AppStore. This allows me to have both the 'official' version and the development version installed on the exact same device without conflict.

What I need is a simple way to control the bundle identifier through a header file. In Xcode, I have specified the following settings:

  1. Preprocess Info.plist File set to Yes;
  2. Info.plist Preprocessor Prefix File set to ux_defines.h.

The ux_defines.h goes as follows:

// Set this to 0 to switch bundle id to official
#define USE_DEBUG_PRODUCT          1


#if (USE_DEBUG_PRODUCT == 1)
#  define MACRO_APPID com.companyname.appname_dbg
#else
#  define MACRO_APPID com.companyname.appname
#endif

In Info.plist, I have specified the Bundle Identifier as follows:

<key>CFBundleIdentifier</key>
<string>MACRO_APPID</string>

However, when I build for the device, Xcode always gives me an error: Failed to code sign "App Name". On the other hand, everything works smoothly if I keep the bundle identifier hard-coded but define a custom option in Info.plist. For example, the following option:

<key>FooBar</key>
<string>MACRO_APPID</string>

...is correctly preprocessed into:

<key>FooBar</key>
<string>com.companyname.appname_dbg</string>

... or

<key>FooBar</key>
<string>com.companyname.appname</string>

... depending on the value of MACRO_APPID in the header. The error seems only specific to the bundle identifier.

How can I set up the project and avoid these errors?

1

1 Answers

0
votes

Not sure how to solve the errors you're getting. However, I can suggest a different method which is slightly more complicated but should work for you:

  1. Create a new build configuration by duplicating an existing one (in project settings navigator -> Info -> Configurations). You can name it "Development" for example.

  2. Create a new scheme for your target by duplicating an existing one and set its Run action to use your new build configuration.

  3. Create 2 xcconfig files - one for each build configuration, both with a variable for your bundle id but with the proper value of the configuration: APP_BUNDLE_ID=com.companyname.appname_dbg and APP_BUNDLE_ID=com.companyname.appname. In your project Info under "Configurations" set the appropriate xcconfig file to each of your build configuration.

  4. Finally, in your Info.plist file, use the variable from the xcconfig - ${APP_BUNDLE_ID}, as your Bundle identifier.

Now you can choose which bundle identifier to use simply by selecting which scheme to run instead of editing a header file.