📜 ⬆️ ⬇️

We generate the version number and build on the iOS application icon



During the development process, the application is tested, and it happens that you need to know which version of the application and which build number of the tester / other participant of the process is installed. For example, the bug is already fixed, but the new build person has not yet installed and complains that nothing has been fixed.

Often this information is hidden somewhere, for example, in the Yandex.Market application, you need to poke into the Cabinet section and select the “About Application” option:
')
Example

For convenience (or because this screen is not yet ready), you can bring this useful information directly to the application icon.

1. Put the necessary packages from Homebrew:

brew install imagemagick brew install ghostscript 

2. Open our project in Xcode, open our Images.xcassets, select AppIcon and see where the files with icons are located:



We see the file names, remember:



In my case, I will only touch the icons for Retina-iPhones.

3. Open Xcode, go to our target settings in the Build Phases section, add the New Run Script Phase:



4. Insert the following code into the Run Script block:

 #     ,      if [ $CONFIGURATION = "Release" ]; then exit fi #   version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}"` #   build=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"` #  ,      git branch=`git rev-parse --abbrev-ref HEAD` #    function processIcon() { export PATH=$PATH:/usr/local/bin base_file=$1 target_icon_name=$2 base_path=`find ${SRCROOT} -name $base_file` if [[ ! -f ${base_path} || -z ${base_path} ]]; then return; fi target_file=`echo $target_icon_name | sed "s/_base//"` target_path="${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}" width=`identify -format %w ${base_path}` echo $target_path echo $target_file convert -background '#0008' -fill white -gravity center -size ${width}x40 -pointsize 26\ caption:"${version} (${build})"\ "${base_path}" +swap -gravity south -composite "${target_path}" } #   processIcon "ewrw_120-1.png" "AppIcon60x60@2x.png" processIcon "ewrw_180.png" "AppIcon60x60@3x.png" 

Is done. When a project is assembled, if the application icons are in Images.xcassets, then inside file.app they have, after the build, names of the form AppIcon60x60@2x.png, AppIcon60x60@3x.png, etc. These are the names and are used in the last 2 lines. You just need to substitute the file names of your icons.

As a result, when we build a debug build, the icon is replaced by a new one, with the version number and build number superimposed below:



I hope someone such a trifle will also be useful.

PS I took the information and drew a little from here (there for the option when assets are not used).

Useful (including in the comments): "Automatic increase in the build number in Xcode"

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


All Articles