如何在 LaunchStoryboard 中显示 CFBundleShortVersionString? [英] How do I display the CFBundleShortVersionString in my LaunchStoryboard?

查看:28
本文介绍了如何在 LaunchStoryboard 中显示 CFBundleShortVersionString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在我的 LaunchStoryboard 中将 CFBundleShortVersionString 显示为 UILabel 文本,而无需每次增加时手动输入它?我知道如何在代码中执行此操作,但无法在显示 LaunchStoryboard 时运行代码.
是否可以通过 Xcode 变量?

Is there any way to display the CFBundleShortVersionString as a UILabel text in my LaunchStoryboard without entering it by hand every time it increments? I know how to do it in code, but it is not possible to run code while the LaunchStoryboard is shown.
Is it possible through Xcode variables?

推荐答案

我想出了更新版本的脚本 &根据第一个答案在 LaunchScreen.storyboard 上构建标签,而无需使用任何额外文件.不幸的是,由于一些语法错误和不正确的路径,Clemens Brockschmidt 的解决方案不起作用.

I figured out the script to update the Version & Build label on LaunchScreen.storyboard based on the first answer without using any extra files. Unfortunately, Clemens Brockschmidt's solution doesn't work due to some Syntax errors and incorrect paths.

确保在身份检查器窗格 -> 文档 -> 标签中将标签命名为APP_VERSION".

Make sure to name your label to "APP_VERSION" in Identity Inspector pane -> Document -> Label.

还要在复制捆绑资源"阶段之前创建脚本.

Also create your script before "Copy Bundle Resources" phase.

更新:我的旧答案在最新的 Xcode 环境中不起作用.我已经修复了当前的问题并重构了脚本.

UPDATE: My older answer didn't work in the newest Xcode environment. I've fixed the current issues and refactored the script.

这是带有 shell 的最终工作脚本:/bin/sh in XCode 11 (Swift 5):

And here's the final working script with shell: /bin/sh in XCode 11 (Swift 5):

#   ON/OFF Script Toggle (script ON with #, script OFF without #)
#exit 0

#   Increment Build Number Bool (Increment ON with true, increment OFF with false)
shouldIncrement=false

#   App vesion / Build version constants
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/Base.lproj/LaunchScreen.storyboard"
versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"


#   Increment build number
if [ "$shouldIncrement" = true ]; then
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi

#   Output version & build numbers into a label on LaunchScreen.storyboard
sed -i .bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$versionNumber($buildNumber)\"/" "$sourceFilePath"

作为一个奖励,我提供了一个内部版本号增量器和 ON/OFF 脚本切换,以在您大量构建项目时禁用增量器.如果您有任何问题或这是否适合您,请告诉我.

As a BONUS I've included a build number incrementer and ON/OFF script toggle to disable your incrementer when you build your project a lot. Let me know if you have any issues or if this works for you.

这篇关于如何在 LaunchStoryboard 中显示 CFBundleShortVersionString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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