Created
July 9, 2019 13:40
-
-
Save alekseypotapov-dev/5cc8c113a0d6407e84daf79c63b62100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Start by adding a label to your LaunchScreen.storyboard: | |
Format the label however you like. I like to use something subtle that you can read when you need to but that isn’t very noticeable otherwise. | |
Set Document/Label to APP_VERSION. You will use this value in the Build Phase script. | |
Continue by adding the custom Build Phase: | |
Select your project in the upper-left-hand corner of Xcode. | |
Select the app target towards the middle of the screen. | |
You should see a strip of tabs that includes General, Capabilities, […], Build Settings, and then Build Phases. | |
Click on the + above the list of build phases and choose New Run Script Phase | |
Rename the phase to something like “Show Version on LaunchScreen”. Xcode can be finicky about this part; if you can’t rename the phase, don’t worry too much about it. | |
Move the phase somewhere above Copy Bundle Resources. | |
Paste the following into the script area: | |
# Output version & build number to the APP_VERSION label on LaunchScreen.storyboard | |
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}") | |
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}") | |
sed -i "" -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"Version: $versionNumber ($buildNumber)\"/" "$PROJECT_DIR/$PROJECT_NAME/Storyboards/Base.lproj/LaunchScreen.storyboard" | |
Note that the path in the sed command must match the path to your LaunchScreen.storyboard. In this project, it’s saved under the main project folder in a folder called Storyboards. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment