How to display CFBundleShortVersionString in my LaunchStoryboard?

Is there a way to show CFBundleShortVersionString as UILabel text in my LaunchStoryboard without manually entering it every time it grows? I know how to do this in code, but it is not possible to run the code while LaunchStoryboard is displayed.
Is this possible with Xcode variables?

+4
source share
3 answers

I found out that the script updated the Version and Build shortcut on LaunchScreen.storyboard based on the first answer without using any additional files. Unfortunately, Clemens Brockschmidt's solution does not work due to some syntax errors and wrong paths.

"APP_VERSION" " " → "" → "".

script " Bundle".

script :/bin/sh XCode 9 (Swift 4):

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

#   Increment build number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

#   Output version & build numbers into a label on LaunchScreen.storyboard
versionNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
sed -i bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"Version: $versionNumber Build: $buildNumber\"/" $PROJECT_DIR/>>>CHANGE ME<<</Base.lproj/LaunchScreen.storyboard

: ' → > CHANGE ME < < < .

, / script. , - .

+2

, . , , ( , Info.plist ).

- script, LaunchScreen.storyboard , script .

, Info.plist. , , script LaunchScreen.storyboard.

:

Info.h .

:

#define APP_VERSION 2.6 // Update this version as needed

Xcode "". Version , , APP_VERSION.

" ". Info. "" Preprocess Info.plist File Yes. Info.plist preprocessing Prefix File Info.h.

, , CFBundleShortVersionString Info.plist Info.h.

, :

, , . " ". APP_VERSION Label. , XML userLabel APP_VERSION.

" ". + , New Run script. , , " ". " Bundle".

. /bin/bash "". :

VERSION=`cat Info.h | grep APP_VERSION | cut -f3 -d' '`

sed -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$VERSION\"/" Storyboard.storyboard > tmp.storyboard

. . tmp.storyboard , , .

:

VERSION=`cat Info.h | grep APP_VERSION | cut -f3 -d' '`

sed -i bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"$VERSION\"/" Storyboard.storyboard

. , , .

+5

. ..

inital VC LaunchScreen.xib .

Now in ViewController you can access the information plist through the NSBundle method and set its value. This will allow you to go from the launch screen to the first chapter of VC and look natural with animation of the version code or something in this case, if you want

let appVersion = NSBundle.mainBundle().infoDictionary["CFBundleVersion"];
 myLabel.text = "\(appVersion)"
-1
source

All Articles