Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: is there a way to get the bundle identifier of a parent project?

Tags:

xcode

xcode4

I have a Xcode project for a mac app that contains another project for a helper app to launch the main app at login. Is there a way I can base the bundle identifier of the helper app off of the main app with a project variable like ${PRODUCT_NAME} but something like ${ROOT_PRODUCT_IDENTIFIER}?

So the main app's bundle identifier would be:

com.mydomain.app

and the helper app's bundle identifier would be:

${ROOT_PRODUCT_IDENTIFIER}.Helpercom.mydomain.app.Helper

My goal with this is to create a really easy to use generic launch at login helper app that any mac app can use, I've got it working in this repo but it requires a couple values to be changed: https://github.com/kgn/LaunchAtLoginHelper

like image 563
keegan3d Avatar asked Apr 20 '12 08:04

keegan3d


1 Answers

I'm afraid the variable you're looking for doesn't exist, have a look here or here

But I can think of one workaround by creating your own environment variable, which isn't difficult. In order to achieve what you want, create a build script for your main project that extracts the identifier and saves it to an environment variable.

Go to your main project's target and click on Add Build Phase -> Add Run Script. In the shell box that appears, type this in:

ROOT_PRODUCT_IDENTIFIER_PLIST=`/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" $INFOPLIST_FILE`
export ROOT_PRODUCT_IDENTIFIER=`eval echo $ROOT_PRODUCT_IDENTIFIER_PLIST`

Now go to your helper's project and reference $(ROOT_PRODUCT_IDENTIFIER) in its plist/build settings.

Remember to add your main project as a dependency for the latter, so that variable is always set by the time its needed.

like image 138
Alejandro Benito-Santos Avatar answered Oct 16 '22 22:10

Alejandro Benito-Santos