Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - Is there a way of automatically writing custom values to the bundle's .plist during a build phase?

I'm setting up a CI system using Jenkins and am using agvtool to bump and set marketing & technical versions at build time.

In addition to setting the versioning at build time it would be very useful to set a couple of of custom values in the .plist.

Is this possible?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can edit the Info.plist at build time by taking advantage of the "Pre-actions" options to run a script.

enter image description here

Here's an example script that increments a Key in the Plist called UserDefinedVersionNumber

#!/bin/sh

#Grabs info from plist
plist=$SRCROOT"/"$INFOPLIST_FILE
currentBuild=`/usr/libexec/PlistBuddy -c "Print :UserDefinedVersionNumber" "$plist"`

#And changes it before writing out the plist again
if [ -z "$currentBuild" ]
then
    currentBuild=1
    /usr/libexec/PlistBuddy -c "Add :UserDefinedVersionNumber string $currentBuild" "$plist"

else
    currentBuild=$(($currentBuild + 1));
    /usr/libexec/PlistBuddy -c "Set :UserDefinedVersionNumber $currentBuild" "$plist"
fi

You should be able to type the script directly into that little box, but I find that editing and maintaining it can become troublesome, especially for shared scripts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...