1

通过自定义脚本,我在构建和运行应用程序时更新了我的 app-info.plist 中的 CFBundleVersion。此信息也用于应用程序中以显示应用程序名称和版本。更新在构建过程中运行良好,但不幸的是旧信息是在应用程序本身中读取的。

例如,当我构建并运行应用程序时,app-info.plist 会更新,CFBundleVersion现在有 value 8,但在模拟器中7会显示 value。

似乎更新的 app-info.plist 没有在构建过程中使用,而是使用旧版本。

如何确保在我的应用中使用更新后的 app-info.plist?一方面,脚本的执行应该是构建过程中的第一件事,或者另一方面 app-info.plist 应该在构建过程中更新。但是对于两个我都不知道该怎么做......

我在 Project > Buildphases > Add Build Phase > Add Run Script 下添加了自定义脚本。具有以下内容:

shell: /bin/bash   Tools/addVersionNumber.sh

工具/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

干杯——杰里克

4

1 回答 1

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 

干杯——杰里克

于 2013-03-22T10:51:34.040 回答