Episode #213

Icon Badging with Fastlane

9 minutes
Published on March 17, 2016

This video is only available to subscribers. Get access to this video and 572 others.

When doing release builds it is handy to automatically update the build number so we always have a unique version for reporting bugs. However it is not easy for testers to always know which version they are testing. In this episode we'll look at how to set up versioning for our project, automatically increment the versions number for release builds, and badge our application's icon so it is easy to see which version of the app you have installed.

Episode Links

Setting up the Project for Versioning

Go to the project and select the versioning strategy to "Apple Generic". Then set the "Current Version" to 1.

Automatically Bumping Build Number

In your Fastlane beta lane, add the following line:

increment_build_number

You'll probably want to commit this change, so you can start your lane with:

ensure_git_status_clean

This will make sure we're in a clean state so we don't accidentally commit other changes along with the version change.

Then we can end the lane with:

commit_version_bump

Tip: If you ever forget what actions are available, type fastlane actions and grep for a keyword.

Badging the App icon

To badge the app icon, we'll use the badge gem. In your Gemfile add:

gem 'badge'

Then run: bundle install.

In your fastlane lane, add:

version = "#{get_version_number}.#{get_build_number}"
badge(shield: "Version-#{version}-blue")

This will modify your actual icons, so it's important to have a copy somewhere in case you can't recover them with git. You can restore the icons to their original state by copying the originals back into the asset catalog.

If you want to use git for this, then you'll want to reset back to HEAD for those specific files. Here's how to do that with fastlane:

app_icon_files = Dir["SimpleClock/**/Icon*.png"]
reset_git_repo(files: app_icon_files)

You'll have to make sure that you have at least one commit of the originals, and this will ensure you don't commit them after badging.

This episode uses Fastlane 1.66.0.