我在xCode中添加了RUN SCRIPT阶段:
echo "***** Running build number script ****"
smallHash=$(git log -1 --format=%h)
buildNumber=$(git rev-list --all --count)
echo "***"$buildNumber"_"$smallHash
INFO_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
echo $INFO_PLIST
defaults write "$INFO_PLIST" CFBundleBuildVersion "$buildNumber""_""$smallHash"
defaults write "$INFO_PLIST" CFBundleShortVersionString "5.9.1"
defaults write "$INFO_PLIST" CFBundleVersion "$buildNumber"
构建代码时,xCode日志显示:
***** Running build number script ****
***4289_b5wa5676
/Users/atif/Library/Developer/Xcode/DerivedData/Rel-cozvcgzvie3redhflbonluvmzhxr/Build/Products/Debug-iphonesimulator/iOSApp.app/Info.plist
但是当我尝试在代码中使用以下语句检测版本时:
Bundle.main.infoDictionary?["CFBundleVersion"] as? String
或
Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
它显示:
UPDATED BY SCRIPT I HAVE WRITTEN
代替:
4289_b5wa5676
好像默认写入不起作用。有帮助吗?