更新 app-info.plist 后的 xcode 仅显示应用程序中可用的旧信息
Posted
技术标签:
【中文标题】更新 app-info.plist 后的 xcode 仅显示应用程序中可用的旧信息【英文标题】:xcode after update app-info.plist only the old information available in the app 【发布时间】:2013-03-21 23:57:16 【问题描述】:当我构建和运行应用程序时,我通过自定义脚本更新了我的 app-info.plist 中的 CFBundleVersion。此信息也用于应用程序中以显示应用程序名称和版本。更新在构建过程中运行良好,但不幸的是旧信息是在应用程序本身中读取的。
例如当我构建并运行应用程序时,app-info.plist 会更新,CFBundleVersion
现在的值是 8
,但在模拟器中会显示值 7
。
似乎在构建过程中没有使用更新的 app-info.plist,而是使用旧版本。
如何确保在我的应用中使用更新后的 app-info.plist? 一方面,脚本的执行应该是构建过程中的第一件事,另一方面,app-info.plist 应该在构建过程中更新。但是对于这两个我都不知道该怎么做......
我在 Project > Buildphases > Add Build Phase > Add Run Script 下添加了自定义脚本。内容如下:
shell: /bin/bash Tools/addVersionNumber.sh
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
干杯——杰里克
【问题讨论】:
【参考方案1】:找到了解决办法。诀窍是 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://***.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
干杯——杰里克
【讨论】:
这看起来像是一个完整的黑客......但它有效!谢谢。顺便说一句,既然您找到了自己的答案,我认为在这里将您自己的答案标记为已接受是可以接受的。以上是关于更新 app-info.plist 后的 xcode 仅显示应用程序中可用的旧信息的主要内容,如果未能解决你的问题,请参考以下文章