Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Changing info.plist during build phase

Tags:

I am trying to do the following:

  1. During the build phase, open a plain text file and read the text
  2. Change the value of a property in info.plist to the value obtained in step 1.

Can I write a shell script for this?

It will be great if someone can guide me to achieve this.

like image 498
Mithin Avatar asked Aug 02 '11 13:08

Mithin


1 Answers

Probably the simplest way is to use PlistBuddy. I have a Run Script phase that looks like this:

BUILD_NUMBER=`git rev-list HEAD --count` INFO_PLIST="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" if [ -f "$INFO_PLIST" ] ; then     oldversion=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$INFO_PLIST"` fi if [ "$BUILD_NUMBER" != "$oldversion" ] ; then     /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$INFO_PLIST" fi 

(Note that starting with Xcode 6, you have to run this after the Copy Bundle Resources phase, because Info.plist isn't copied to the target location until then and PlistBuddy would fail.)

Edit 01/17: Updated to avoid unnecessary copying or signing of targets. You don’t want to touch Info.plist unless something really changes, otherwise Xcode will treat it (and thus the target) as modified. Checking previous value CFBundleVersion can significantly speed up builds — it saved me several seconds on noop build.

like image 79
Václav Slavík Avatar answered Sep 28 '22 03:09

Václav Slavík