LaunchScreen xib and displaying application version number from plist

I created LaunchScreen in Xcode and appears with the default application name and copyright notice. However, I would like to show the version number, but I would prefer to pull the version number from Info.plist, instead of changing a few places whenever the version number changes. Is this possible or do I need to abandon LaunchScreens and create a SplashScreenViewController to achieve this?

+5
source share
2 answers

Although it may now be xib instead of bitmaps, the application launch screen still cannot execute any application code. This is static in essence. Thus, it is not possible to include the version number from plist in the startup screen. Unless, of course, you manage to add some kind of assembly action to edit the launch screen (be it xib or bitmap images).

+5
source

Here's how I did it with custom build rules. The basic idea is to add a placeholder string, which will be replaced with the correct version during the build process. Then the version will return to the placeholder text.

  • Create a script file $PROJECT_DIR/Scripts/splash-version.sh with the contents:

IMPORTANT : Browse the XIB and PLIST paths to those used by your project.

 #!/bin/bash xib_file="$PROJECT_DIR/Base.lproj/LaunchScreen.xib" # CHECK this path plist_file="$PROJECT_DIR/$TARGET_NAME.plist". # CHECK this path bundle_ver=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$plist_file") bundle_short_ver=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$plist_file") str_ver="v$bundle_short_ver($bundle_ver)". # You can edit this. Beware this is used by sed as a regex placeholder_ver="#version#" # You can edit this if [ "$1" == "set" ]; then if ! grep "$placeholder_ver" "$xib_file" >/dev/null; then echo "Version placeholder $placeholder_ver not found in XIB file $xib_file" exit 1 fi sed -i -e "s/$placeholder_ver/$str_ver/" "$xib_file" elif [ "$1" == "reset" ]; then sed -i -e "s/$str_ver/$placeholder_ver/" "$xib_file" else echo "syntax: $0 set | reset" exit 1 fi 
  1. Add Execution Permissions

  2. Add a new shortcut to your XIB file with the text #version# . This is a placeholder string that will be replaced with a script with the correct version

  3. Add "New Run script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" set

  4. Move it just before the "Copy Resources" phase

  5. Add "New Run script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" reset

  6. Move it only after to the "Copy Resources" section. These steps return the version string back to the placeholder string.

+1
source

Source: https://habr.com/ru/post/1206214/


All Articles