Xcode: pass bundle id as environment variable to extension
Asked Answered
T

2

4

I need to build an Xcode project within a Today Extension by 'xcodebuild'. The bundle is of the main target is com.myapp, while the bundle id of the extension is com.myapp.todayextension. I'd like to pass both the bundle id's as parameters of xcodebuild: I tried to replace the bundle id's in the xcode project by custom environment variables (e.g. ${MAIN_TARGET_BUNDLEID} and ${EXTENSION_BUNDLEID}) but the xcodebuild fails. Could you please help me with the correct syntax of xcodebuild command ? Thanks.

Timeconsuming answered 5/2, 2016 at 17:46 Comment(0)
F
1

Better too late than never; We can't directly use an environment variable in General tab, you will need to go into Build Settings tab, then set Product Bundle Identifier to your environment-variable, for example $(PRODUCT_NAME).

See below for another approach.

How to load prefix set by parent project?

  1. Create an .xcconfig file (with content like example).
  2. Set up the .xcconfig file in project settings's Info tab (not target's Info tab).
  3. In target's Build Settings tab, ensure PRODUCT_BUNDLE_IDENTIFIER is not bold (click it and press delete).

But Podfile users should see also: How to make Xcode use multiple xcconfig files?

Example

My extension.xcconfig file (which is in MyApp/MyLib/MyExtension directory), looks something like:

// Below loads `MyApp/config/mylib.xcconfig` file.
#include "../../config/mylib.xcconfig"

PRODUCT_BUNDLE_IDENTIFIER = $(MYLIB_BUNDLE_PREFIX).$(PRODUCT_NAME)

Note that:

  1. You want to use some environment as prefix, but above I use PRODUCT_NAME as suffix (simply edit as you wish).
  2. The mylib.xcconfig file sets MYLIB_BUNDLE_PREFIX, and is outside of my MyLib.xcodeproj file's directory (so is in parent project's config directory, I describe in MyLib's README.md that users should create it there).
  3. So, beside showing my #include approache, I try to introduce use of environment-variable.
Flasket answered 1/9, 2021 at 3:58 Comment(0)
Z
0

That's called PRODUCT_BUNDLE_IDENTIFIER, as per the documentation.

A string that uniquely identifies the bundle. The string should be in reverse DNS format using only alphanumeric characters (A-Z, a-z, 0-9), the dot (.), and the hyphen (-). This value is used as the CFBundleIdentifier in the Info.plist of the built bundle.

Zampino answered 29/3, 2021 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.