1、在Build Phases中新建一个脚本,比如起名叫:【Build Config】
myFile="BuildConfig.plist"
myDate=`date +%Y-%m-%dT%H:%M:%S%z`
echo $myDate
myHash=`git rev-parse --short HEAD`
echo $myHash
if [ ! -f"$myFile"]; then
/usr/libexec/PlistBuddy -c"Add :BUILD_TIME string $myDate""$myFile"
/usr/libexec/PlistBuddy -c"Add :GIT_SHA string $myHash""$myFile"
else
/usr/libexec/PlistBuddy -c"Set :BUILD_TIME $myDate""$myFile"
/usr/libexec/PlistBuddy -c"Set :GIT_SHA $myHash""$myFile"
fi
2、会在工程目录下生成BuildConfig.plist文件,内容如下:
3、代码中获取时间并显示:
if(IS_DEV_VERSION) {//注意只在测试环境使用
NSDictionary*buildInfo = [MMUtilsbuildConfiguration];
versionStrAddition = [NSStringstringWithFormat:@"\nBUILD_TIME:%@\nGIT:%@", buildInfo[@"BUILD_TIME"], buildInfo[@"GIT_SHA"]];
versionStr = [versionStrstringByAppendingString:versionStrAddition];
//versionStr就是你的得偿所愿
}