如何使用脚本读取Xcode 11中的当前应用程序版本 [英] How to read current app version in Xcode 11 with script

查看:306
本文介绍了如何使用脚本读取Xcode 11中的当前应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 11 之前,我使用了一个脚本来读取当前应用程序版本(适用于AppStore),并帮助我更改了LaunchScreen,因为我们不能为此使用swift.

Until Xcode 11, I used a script that reads the current app version (for the AppStore) and help me change the LaunchScreen since we can't use swift for that.

sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")

sed -i .bak -e "/userLabel=\"APP_VERSION_LABEL\"/s/text=\"[^\"]*\"/text=\"v$versionNumber\"/" "$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"

但是在 Xcode 11 中,项目的构建设置中有一个名为"版本

But in Xcode 11 there is a new section inside the project's build settings called Versioning

CFBundleShortVersionString自动更改为$(MARKETING_VERSION). Xcode会自动处理该问题,并且我不想手动将其更改为静态数字,而让Xcode起作用.

And CFBundleShortVersionString automatically changed to $(MARKETING_VERSION). Xcode automatically handles that and I don't want to change it manually to an static number and let Xcode do it's work.

所以问题是如何使用运行脚本将其访问新的MARKETING_VERSION并将其设置为launchScreen标签?

So the question is how can I access this new MARKETING_VERSION and set it to my launchScreen label using run script?

推荐答案

您可以像使用其他任何项目变量一样使用它:

You can use it like any other project variable:

sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"
versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"

sed -i .bak -e "/userLabel=\"APP_VERSION_LABEL\"/s/text=\"[^\"]*\"/text=\"v$versionNumber\"/" "$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"

这篇关于如何使用脚本读取Xcode 11中的当前应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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