Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

xcode - iOS: Changing info.plist during build phase

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" ] ; 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...