如何获取XCode以添加构建日期&时间到Info.plist文件 [英] how to get XCode to add build date & time to Info.plist file

查看:146
本文介绍了如何获取XCode以添加构建日期&时间到Info.plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后...经过几年的观看和一个月的参与,我有机会问你们一个我自己的问题.

Finally... after a couple years of watching and a month of participating, I have a chance to ask you guys a question of my own.

我的老板不信任我(或任何过程)增加内部版本号,他还希望获得内部日期&时间烘焙到应用程序中.我想将其放入通常的Info.plist文件中.

My boss doesn't trust me (or any process) to increment a build number, he also wants to have a build date & time baked into the app. I'd like to put this into the usual Info.plist file.

我发现了这个相关问题:

I found this related question:

在iOS应用程序中构建信息(日期/时间应用已构建)

根据那里的答案,我进入了方案编辑器,并将下面的脚本添加到了Build阶段的"Post-Action"部分:

and based on the answers there, I went into the Scheme Editor and added the script below to the "Post-Action" section of the Build phase:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
if [[ -n "$builddate" ]]; then
    defaults write "${infoplist%.plist}" BuildDate "${builddate}"
fi

在XCode中,我的方案编辑器"窗口如下所示:

In XCode, my Scheme Editor window looks like this:

不幸的是,BuildDate从未写入Info.plist.

Unfortunately, BuildDate never gets written into Info.plist.

将"$ {builddate}"更改为"$ builddate"也不起作用.我在脚本中添加了这一行:

Changing "${builddate}" to "$builddate" doesn't work either. I added this line to the script:

echo "build date is $builddate" > /tmp/result.txt

,日期在写出的文件中看起来很好.从上面的脚本将字符串写入Info.plist文件中可以很好地完成工作,这很烦人.

and the date appeared perfectly fine in the written out file. Writing strings into the Info.plist file from the above script works perfectly fine, annoyingly enough.

因此,总而言之,如何获取要添加到Info.plist文件中的日期?

So, summed up, how to get the date to be added to the Info.plist file?

推荐答案

Michael回答中的代码不正确或不再更新.下面的版本修复了设置语法中的错误,还支持其中带有空格的构建路径.

The code in Michael's answer is incorrect or no longer up to date. The version below fixes an error in the set syntax and also supports build paths with spaces in them.

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
if [[ -n "$builddate" ]]; then
    # if BuildDateString doesn't exist, add it
    /usr/libexec/PlistBuddy -c "Add :BuildDateString string $builddate" "${infoplist}"
    # and if BuildDateString already existed, update it
    /usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}"
fi

注意:此更改是作为修改提交的,但遭到拒绝,而且我还没有足够的声誉对他的答案发表评论...

Note: This change was submitted as an edit but got rejected and I don't yet have enough reputation to post a comment on his answer...

这篇关于如何获取XCode以添加构建日期&时间到Info.plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆