read

Every new version uploaded to iTunes Connect needs to have a different build number in order to differentiate the version.

Note: Build number (eg. 1234) is different from Version number (eg. 1.2).

The build number can be automatically increased in these few ways:

Bump in a build script

Create a Run Script in your project Build Phases

#!/bin/bash
bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
bN=$(expr $bN + 1)
bN=$(printf "%d" $bN)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "$INFOPLIST_FILE"

This will auto increment the build number every time you build the project.

Make use of git commits

If you work in a team, the previous build script will pose an unsyncronized problem.

As an improvement, you can use the total number of commits in your git repository as your build number!

#!/bin/bash
if [ ${CONFIGURATION} == "Release" ]; then
buildNumber=$(git rev-list HEAD | wc -l | tr -d ' ')
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi;

avgtool

Apple provide a tool to manage the build and version number.

Firstly, setup the project in order to use avgtool.

This is how you use it:

# In your project folder
# Let's check the current build number
agvtool what-version

# To auto increment the build number
agvtool next-version -all

# To set build number to a specify number eg. 1234
agvtool new-version -all 1234

# You can also set VERSION NUMBER eg 1.2
agvtool new-marketing-version 1.2

Using fastlane

fastlane makes use of agvtool to bump the build number.

In any lane of Fastfile, you can add increment_build_number, which will basically call agvtool next-version -all

UPDATE 2023: The Best Way for CI

If you’re bumping for CI, then relying on where you distribute the app is the right way. Refer to this post on how you can add such a lane in your CI.


Image

@samwize

¯\_(ツ)_/¯

Back to Home