Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read current app version in Xcode 11 with script

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" 

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

enter image description here

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.

11

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

like image 347
Mojtaba Hosseini Avatar asked Jun 23 '19 09:06

Mojtaba Hosseini


People also ask

What is CFBundleShortVersionString?

CFBundleShortVersionString (String - iOS, OS X) specifies the release version number of the bundle, which identifies a released iteration of the app. The release version number is a string comprised of three period-separated integers.

What is Current_project_version?

Changing CURRENT_PROJECT_VERSION modifies values within your project's project. pbxproj file and if you are running a distributed team, this will cause merge conflicts if the other half of the team tries to update and while they were asleep, you updated this internal value.


2 Answers

Xcode 11/12

In terminal or bash script in your project you can use:

App version

xcodebuild -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION =' // will be displayed 1.1.6

Build version

xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION =' // will be displayed 7

Or (don't forget to change YouProjectName to your project name):

App version

cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '

Build version

cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'CURRENT_PROJECT_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '

Or slower method (Thx Joshua Kaden):

App version

xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "MARKETING_VERSION" | sed 's/[ ]*MARKETING_VERSION = //'

Build version

xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "CURRENT_PROJECT_VERSION" | sed 's/[ ]*CURRENT_PROJECT_VERSION = //'

like image 160
A.Kant Avatar answered Sep 28 '22 02:09

A.Kant


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" 
like image 23
Nanunana Avatar answered Sep 28 '22 03:09

Nanunana