如何让 XCode 添加构建日期& Info.plist 文件的时间

发布于 2024-12-13 04:09:02 字数 1178 浏览 0 评论 0原文

终于……经过几年的观看和一个月的参与,我有机会问你们一个我自己的问题。

我的老板不信任我(或任何流程)来增加内部版本号,他还希望有一个内部版本号和内部版本号。时间已融入应用程序中。我想将其放入通常的 Info.plist 文件中。

我发现了这个相关问题:

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

并根据那里的答案,我进入方案编辑器并将下面的脚本添加到构建阶段的“操作后”部分:

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

在 XCode 中,我的方案编辑器窗口看起来像这样:


(来源:
myke at maniac.deathstar.org)< /sub>

不幸的是,BuildDate 永远不会被写入 Info.plist。

将“${builddate}”更改为“$builddate”也不起作用。我将这一行添加到脚本中:

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

并且日期在写出的文件中显示得非常好。从上面的脚本将字符串写入 Info.plist 文件工作得很好,但也够烦人的。

那么,总结一下,如何获取要添加到 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.

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:

Build information in iOS Application (date/time app was built)

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

In XCode, my Scheme Editor window looks like this:


(source: myke at maniac.deathstar.org)

Unfortunately, BuildDate never gets written into Info.plist.

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

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你是我的挚爱i 2024-12-20 04:09:02

啊啊,在发布我自己的问题之前,我应该再花 30 分钟(在我已经浪费了 2 个小时的基础上)查看这个问题的答案:

在 Xcode 中插入 Subversion 修订号

这个后操作脚本可以解决问题并且对我有用:

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

如您所见,它在那里做了一些修改(如果它不存在则添加它;然后设置它)。

如果有人可以使用上面的“默认写入”方法建议一个解决方案(我认为这可能比“PlistBuddy”得到更好的支持),我会很高兴发现(当然我会接受并使用这个更好的答案,也)。

Ahhhh, I should have spent another 30 minutes (on top of the 2 hours I had already wasted) and looked at the answers for this question before posting my own:

Insert Subversion revision number in Xcode

This post-action script does the trick and works for me:

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

As you can see, it's doing a bit of a hack there (adding it if it doesn't exist; setting it right afterwards).

If anyone can suggest a solution using the "defaults write" method above (which I think might be better supported than "PlistBuddy"), I'd be thrilled to find out (and of course I'll accept and use that superior answer, too).

水中月 2024-12-20 04:09:02

迈克尔的答案中的代码不正确或不再是最新的。下面的版本修复了设置语法中的错误,并且还支持其中包含空格的构建路径。

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

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

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...

素食主义者 2024-12-20 04:09:02

我正在使用您的确切代码,但在预操作而不是后操作中,并且构建产品中的 info.plist 正确报告了构建日期。换句话说,在将 info.plist 复制到构建的产品中之前,您必须对其进行自定义,这对我来说听起来很合理。

顺便说一下,感谢您的建议,它非常聪明且有用。

I am using your exact code, but within the pre-action instead of the post-action, and the info.plist within the built product correctly reports the build date. In other words, you have to customize your info.plist before copying it into the built product, which sounds reasonable to me.

By the way, thanks for the suggestion, it's pretty clever and useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文