自动将日期/时间和内部版本号添加到Info.plist Xcode

我希望自动将构建日期和内部版本号添加到我的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__预处理器指令.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...