I have created a LaunchScreen in Xcode and it appears with the default application title and copyright notice. However I would like to display the version number but I would rather pull the version number from the Info.plist rather than having to modify several places whenever the version number changes. Is this possible or do I need to give up on LaunchScreens and create a SplashScreenViewController to achieve this?
Although it can now be a xib instead of bitmaps, the app launch screen still cannot execute any kind of application code. It's static, essentially. So it isn't possible to include a version number from a plist in your launch screen. Unless of course you manage to add some sort of build action to edit the launch screen (be it a xib or bitmaps).
This is how I have done it with custom build rules. The basic idea is to add a placeholder string that will be replaced during the build process with proper version. The version is then reverted to the placeholder text.
$PROJECT_DIR/Scripts/splash-version.sh
with contents:IMPORTANT: Review XIB and PLIST paths match the ones 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 execute permissions
Add a new label in your XIB file with the text #version#
. This is the placeholder string that will be replaced by the script with the proper version
Add a "New Run Script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" set
Move it just before the "Copy Bundle Resources" phase
Add a "New Run Script Phase" and set the command "$PROJECT_DIR/Scripts/splash-version.sh" reset
Move it just after the "Copy Bundle Resources" phase. This steps reverts the version string back to the placeholder string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With