我希望自动将构建日期和内部版本号添加到我的Info.plist文件中,仅用于存档iOS应用程序的构建.
我的脚本如下
#!/bin/bash # This was taken from variations from: # http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode if [ "$CONFIGURATION" != "Release" ] then exit fi buildPlist="$SRCROOT/$PROJECT_NAME/$PROJECT_NAME-Info.plist" # Get the existing buildVersion and buildNumber values from the buildPlist buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBuildVersion" "$buildPlist") buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" "$buildPlist") buildDate=$(date "+%s") # Increment the buildNumber buildNumber=$(($buildNumber + 1)) # Set the version numbers in the buildPlist /usr/libexec/PlistBuddy -c "Set :CFBuildNumber $buildNumber" "$buildPlist" /usr/libexec/PlistBuddy -c "Set :CFBuildDate $buildDate" "$buildPlist" /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildVersion.$buildNumber" "$buildPlist" /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildVersion.$buildNumber" "$buildPlist" /usr/libexec/PlistBuddy -c "Set :CFBundleLongVersionString $buildVersion.$buildNumber.$buildDate" "$buildPlist"
这里的一切都很好用,我在构建阶段选项卡中的目标依赖项之后立即将此脚本作为构建阶段运行.
我唯一的问题是该项目似乎是使用Info.plist的旧值而不是新的值构建的.
换句话说,如果我归档应用程序并检查生成的ipa中的Info.plist文件,它们会反映旧值.但是,查看项目中的Info.plist会显示脚本确实正确执行,但是没有及时使用旧的Info.plist构建项目.
这有什么解决方案吗?
解决方法
事实证明,答案非常简单明了.所有必要的是打开Info.plist预处理,然后使用__TIMESTAMP__预处理器指令.