通过自定义脚本我在构建和运行应用程序时在我的app-info.plist中更新我的CFBundleVersion。此信息也在应用程序中用于显示应用程序名称和版本。更新在构建过程中工作正常,但不幸的是旧的信息在应用程序本身中读取。
E.g。当我构建并运行app app-info.plist时,CFBundleVersion
现在具有值8
,但在模拟器中显示值7
。
似乎所以更新的app-info.plist不会在构建过程中使用,而是使用旧版本。
如何确保在我的应用中使用更新的app-info.plist? 一方面,脚本的执行应该是构建过程中的第一件事,或者另一方面应该在构建过程中更新app-info.plist。但对于两者我都不知道该怎么做......
我在Project>下添加了自定义脚本构建阶段>添加构建阶段>添加运行脚本。具有以下内容:
shell: /bin/bash Tools/addVersionNumber.sh
#/bin/bash
# script that should be executed in the build phase
# to set the build number correct
plist="app-folder/app-Info.plist"
## get git information
# git_rev_full_hash=$( git rev-parse HEAD )
git_amount_commits=$( git rev-list HEAD | wc -l )
git_rev_short_hash=$( git rev-parse --short HEAD )
buildRevision="$git_amount_commits: $git_rev_short_hash"
# set build revision ( git short hash - amount of commits )
/usr/libexec/PlistBuddy -c "Set :BuildRevision $buildRevision" $plist""
## build number
buildNumber=$( /usr/libexec/PlistBuddy -c "Print CFBundleVersion" $plist )
buildNumber=$(( $buildNumber + 1 ))
# set new build number
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" $plist
欢呼 - jerik
答案 0 :(得分:3)
找到解决方案。诀窍是build文件夹中的info.plist和dsym(?)中的plist也必须更新。
我的脚本现在看起来像这样
#/bin/bash
# script that should be executed in the build phase
# to set the build number correct
#
# http://www.cimgf.com/2008/04/13/git-and-xcode-a-git-build-number-script/
# http://stackoverflow.com/questions/7944185/how-to-get-xcode-to-add-build-date-time-to-info-plist-file
# http://www.danandcheryl.com/2012/10/automatic-build-numbers-for-ios-apps-using-xcode
# Marketing Number is in CFBundleShortVersionString - will be edited manually
# @TODO add logging
plist="app-folder/app-Info.plist"
build_plist=$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH
conInfo="Contents/Info.plist"
dsym_plist=$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/$conInfo
function writePlist( ) {
# set build revision ( git short hash - amount of commits )
/usr/libexec/PlistBuddy -c "Set :BuildRevision $buildRevision" $1
# set build date
/usr/libexec/PlistBuddy -c "Set :BuildDate $buildDate" $1
#set build number
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" $1
}
# git_rev_full_hash=$( git rev-parse HEAD )
buildRevision=$( git rev-parse --short HEAD )
git_rev_plist_hash=$( /usr/libexec/PlistBuddy -c "Print BuildRevision" $plist )
# Only update version if a commit was performed. Avoid update version when in development cycle
if [[ $git_rev_plist_hash != $buildRevision ]]; then
### variables for updating plist
# set new build number and date
buildNumber=$( /usr/libexec/PlistBuddy -c "Print CFBundleVersion" $plist )
buildNumber=$(( $buildNumber + 1 ))
buildDate=$(date "+%Y-%m-%d %T %z %Z")
writePlist $plist
writePlist $build_plist
writePlist $dsym_plist
fi
欢呼 - jerik