iOS 应用程序中的构建信息(构建日期/时间应用程序) [英] Build information in iOS Application (date/time app was built)

查看:35
本文介绍了iOS 应用程序中的构建信息(构建日期/时间应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,可以在 iOS 应用程序的构建过程中动态添加有关应用程序的信息.

I'm looking for a way to dynamically add in information about the application during the build process of an iOS application.

在测试期间,很高兴知道我在设备上安装的应用程序是何时构建的,并且可能知道是谁构建的应用程序也很不错.

During testing, it would be great to know when the application I have installed on my device was built and possibly who built it would be a good to know as well.

我正在设想 settings.app 中的一个部分,它将提供用于调试目的的基本构建信息.我不想在每次构建之前手动更新构建信息文件 - 数据应该动态生成.

I'm envisioning a section in settings.app that would give basic build information for debugging purposes. I don't want to have to manually update a build information file before each build - the data should be generated dynamically.

推荐答案

您可以在 Xcode 中编写一个 shell 脚本构建阶段,该阶段在构建过程结束时运行.在此阶段,您可以使用 defaults 命令将数据写入任意文件.我已经使用这种技术写入 Info.plist 文件,但您可以写入任何您想要的文件[1].

You can write a shell script build phase in Xcode that runs at the end of your build process. In this phase you can use the defaults command to write data to an arbitrary file. I've used this technique to write to the Info.plist file, but you can write to any file you want[1].

这是将当前 git 版本写入 Info.plist 的示例脚本:

Here's a sample script to write the current git version to Info.plist:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
gitversion="$(cd "$SRCROOT" && git describe --always --dirty 2>/dev/null)"
if [[ -n "$gitversion" ]]; then
    defaults write "${infoplist%.plist}" GitVersion "$gitversion"
fi

您应该能够调整它以指向您想要的文件(例如您的设置包)并写入您想要的信息.

You should be able to adapt this to point to the file you want (e.g. your Settings bundle) and write the info you want.

[1] 写入 Info.plist 时要小心,Xcode 有一些错误会阻止它在构建期间实现 Info.plist 更改,这可能会在进行设备构建时破坏配置.

[1] Be careful if you write to Info.plist, Xcode has bugs that can prevent it from realizing Info.plist changed during the build, which can break the provisioning when doing a device build.

这篇关于iOS 应用程序中的构建信息(构建日期/时间应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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