<h2>第一步</h2>
先在Info.plist中新增一个行,key名字为:buildTime value不用设值。
<h2>第二步</h2>
选中Application工程target-》buildPhase-》在copy 资源前,添加如下脚本:
#执行文件名字,一般跟创建工程文件夹名字相同
EXECUTABLE_NAME="${EXECUTABLE_NAME}"
#工程目录路径
PROJECT_DIR="${PROJECT_DIR}"
EXECUTABLE_NAME="${EXECUTABLE_NAME}"
#工程plist路径
project_infoplist_path="${PROJECT_DIR}/${EXECUTABLE_NAME}/Info.plist"
#echo $project_infoplist_path > ${PROJECT_DIR}/${EXECUTABLE_NAME}/project_infoplist_path.txt
#编译时间
buildTime=`date +%Y-%m-%d'+'%H:%M`
#echo $buildTime > ${PROJECT_DIR}/${EXECUTABLE_NAME}/buildTime.txt
#echo $buildTime > ${PROJECT_DIR}/buildTime.txt
#修改的命令行
modifyCmdString="'""Set :buildTime"" "${buildTime}"'"
#echo $modifyCmdString
destinationCmd="/usr/libexec/PlistBuddy -c "${modifyCmdString}" ${project_infoplist_path}"
#echo "cmd :\n "${destinationCmd}
#解决无法使用``进行执行问题,执行PlistBuddy处理Info.plist
a="/usr/libexec/PlistBuddy"
a2="-c"
b="'Set :buildTime ${buildTime}'"
c="${project_infoplist_path}"
eval ${a}" "${a2}" "${b}" "${c}
buildPhrase脚本添加结果示意:
image.png
<h2>如何在程序中显示?</h2>
代码如下:
#ifdef DEBUG
_appBuild = [NSString stringWithFormat:@"%@_(%@)",infoDic[@"innerBuild"],infoDic[@"buildTime"]];
#else
_appBuild = infoDic[@"innerBuild"];
#endif
网友评论