如果您嘗試在Xcode編譯構建階段中設置該值,您可能會遇到麻煩,因爲我不知道任何解釋操作都會與您嘗試設置您的方式的設置發生正試圖設置它們。
用於自動設置版本號,我有一個更復雜的半自動版本和自動編號方案,所以我不必記住要更改或者所以我可以給一個版本號我但是始終增加內部版本號,並且在這兩種情況下,它都會將內部版本號放入iOS系統設置中顯示的應用程序設置的「關於」框中。
你可能不需要太多任何東西,但是有一些技巧用於獲取和編寫信息,這些信息可能會對您有所幫助,並可能爲您的問題找到解決方案。
以下腳本是由堆棧溢出的答案如何做到這一點,我不能在此刻找到靈感。由於(a)我希望版本號顯示在系統設置中顯示的設置中;和(b)Xcode緩存Info.plist文件的內容,所以這樣做並不像我期望的那麼簡單。
在到來之前編譯,我運行一個構建階段
以下(含安裝選中只有當運行腳本)
sh xolawareStashProductSettings.sh
xolawareStashProductSettings.sh的內容檢查信息的git的狀態.plist文件,如果不是乾淨的,暫時存放它以備以後恢復。
#!/bin/sh
#
# should be run prior to the Copy Bundle Resources step
# and prior to any version information modifier scripts
INFOPLIST_GIT_PATH=${PROJECT}/`basename ${INFOPLIST_FILE}`
echo "-- Temp Hold ${INFOPLIST_GIT_PATH} Script --"
set -e
# a fallback in case the user has made changes to the file
if [ `git status --porcelain ${INFOPLIST_GIT_PATH} ]|wc -l` -gt 0 ]; then
echo cp -p ${INFOPLIST_GIT_PATH} ${TARGET_TEMP_DIR}
cp -p ${INFOPLIST_GIT_PATH} ${TARGET_TEMP_DIR}
fi
腳本#2(與安裝未選中僅當運行腳本):
sh xolawareStashSettingsBundleRootPlist.sh
xolawareStashSettingsBundleRootPlist.sh的內容類似於腳本的內容1.
#!/bin/sh
#
# should be run prior to the Copy Bundle Resources step
# and prior to any version information modifier scripts
echo '-- Temp Hold Settings.bundle/Root.plist Script --'
ROOT_PLIST=${PROJECT}/Resources/Settings.bundle/Root.plist
set -e
# a fallback in case the user has made changes to the file
if [ `git status --porcelain ${ROOT_PLIST} ]|wc -l` -gt 0 ]; then
echo cp -p ${ROOT_PLIST} ${TARGET_TEMP_DIR}
cp -p ${ROOT_PLIST} ${TARGET_TEMP_DIR}
fi
腳本#3(與僅在安裝時運行腳本檢查)
sh xolawareIncrementProductSettingsBuildNumber.sh
xolawareIncrementProductSettingsBuildNumber的內容通過一個使用plistbuddy來看看它是什麼和凹凸它:只有
#!/bin/sh
#
# this should be prior to xolawareAboutInfoVersionInfoInSettings.sh
echo "-- Auto-Increment ${INFOPLIST_FILE} Build Version Install Script --"
PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c"
CONFIGURATION_BUILD_SETTINGS_PATH=${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}
CFBV=$(${PLISTBUDDYCMD} "Print :CFBundleVersion" ${PRODUCT_SETTINGS_PATH})
if [[ "${CFBV}" == "" ]]; then
echo "No build number in ${PRODUCT_SETTINGS_PATH}"
exit 2
fi
CFBV=$(expr $CFBV + 1)
set -e
echo ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${PRODUCT_SETTINGS_PATH}"
${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${PRODUCT_SETTINGS_PATH}"
echo ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
腳本#4(與運行腳本安裝選中時)
sh xolawareProductSettingsShortVersion-from-git.sh
sh xolawareAboutInfoVersionInfoInSettings.sh
xolawareProductSettingsSortortVersion-from-git的內容依賴於我在git中恰當地標記我的分支,但如果我忘記了,它將使用自上次提交以自動爲我的版本生成的提交數量。
#!/bin/sh
#
# this should be run after xolawareStashSettingsBundleRootPlist.sh
# and prior to xolawareAboutInfoVersionInfoInSettings.sh
echo '-- Get Product Settings Short Version String from git describe --'
PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c"
CONFIGURATION_BUILD_SETTINGS_PATH=${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}
CFBVS=`git describe|awk '{split($0,a,"-"); print a[1]}'`
CFBVSI=`git describe|awk '{split($0,a,"-"); print a[2]}'`
if [[ "$CFBVSI" != "" ]]; then
CFBVS=${CFBVS}.${CFBVSI}
fi
set -e
echo ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}"
${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}"
echo ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
xolawareAboutInfoVersionInfoInSettings.sh的內容放置在內容關於框中我Root.plist像我想要的。它依靠關於框是在你的settings.bundle的Root.plist的第一件事:
#!/bin/sh
#
# this should be invoked after xolawareStashInfoAndRootPlist.sh,
# xolawareIncrementProductSettingsBuildNumber.sh and
# xolawareProductSettingsShortVersion-from-git.sh, and before
# the regular Copy Bundle Resources Build Phase
echo '-- Auto-Insert Version Info In System Settings Script --'
PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c"
ROOT_PLIST=${PROJECT_DIR}/${PROJECT}/Resources/Settings.bundle/Root.plist
CFBSVS=`exec -c ${PLISTBUDDYCMD} "Print :CFBundleShortVersionString" ${PRODUCT_SETTINGS_PATH}`
CFBV=`exec -c ${PLISTBUDDYCMD} "Print :CFBundleVersion" ${PRODUCT_SETTINGS_PATH}`
set -e
echo ${PLISTBUDDYCMD} "Set :PreferenceSpecifiers:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PLIST}
${PLISTBUDDYCMD} "Set :PreferenceSpecifiers:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PLIST}
也有一對夫婦清理腳本進行了編譯,鏈接&複製捆綁資源相
後運行
sh xolawareStashRestoreSettingsBundleRootPlist.sh
這可能不是必須的,但我調整了Root.plist中的其他項目以便發佈構建,因此這將恢復調試構建的這些設置。
#!/bin/sh
#
# should be run as the second to last script in Build Phases, after the Copy Bundle Resources Phase
echo "-- Manual Restore $INFOPLIST_FILE Script --"
ROOT_PLIST=${PROJECT}/Resources/Settings.bundle/Root.plist
set -e
# first, see if it was stashed earlier due to uncommitted changes
if [ -e ${TARGET_TEMP_DIR}/Root.plist ]; then
echo mv ${TARGET_TEMP_DIR}/Root.plist ${ROOT_PLIST}
mv ${TARGET_TEMP_DIR}/Root.plist ${ROOT_PLIST}
# the better option when available: restore to the pristine state
elif [ `git status --porcelain ${ROOT_PLIST}|wc -l` -gt 0 ]; then
echo git checkout -- ${ROOT_PLIST}
git checkout -- ${ROOT_PLIST}
fi
,最後的步驟自動標記的混帳回購協議,如果我還沒有標記的項目剛纔自己:
sh xolawareProductSettings-git-commit-and-tag.sh
#!/bin/sh
#
# this should be run after xolawareAboutInfoVersionInfoInSettings.sh
# and xolawareProductSettingsShortVersion-from-git.sh
echo "-- ${INFOPLIST_FILE} git commit & tag Install Script --"
SCRIPT_VERSION=`/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' ${INFOPLIST_FILE}`
SCRIPT_BUILD_NUMBER=`/usr/libexec/Plistbuddy -c 'Print :CFBundleVersion' ${INFOPLIST_FILE}`
if [ `git status --porcelain ${SCRIPT_INFO_PLIST}|wc -l` -gt 0 ]; then
echo git commit -m '"'version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}'"' ${INFOPLIST_FILE}
git commit -m "version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}" ${INFOPLIST_FILE}
fi
echo git tag -f ${SCRIPT_VERSION}
git tag -f -F /dev/null ${SCRIPT_VERSION}
我遇到了這個問題,以及創造一個新的問題: http://stackoverflow.com/questions/31524925/compilation-flags-using-bash-in-xcode/31541953#31541953 我知道這已經有幾年了,現在可能不適用於你,但我也管理過去它的工作(看我的答案在同一頁) – kotakotakota