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

拥有回忆 提交于 2019-11-29 14:53:21

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!