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
Add Execution Permissions
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
Add "New Run script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" set
Move it just before the "Copy Resources" phase
Add "New Run script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" reset
Move it only after to the "Copy Resources" section. These steps return the version string back to the placeholder string.
source share