Kinda Fixing Badge Truncation

While I’ve been working on the next update to Pedometer++ I ran into a curious bug. Pedometer lets you optionally badge the app icon with your current daily step count. This allows you to see how you are doing without having to open the app.

Unfortunately, on iOS 7 whenever you ask an application to set its badge to a number greater than 9,999 there is a very good chance the badge will be shown as a rather awful truncated string. This is especially unfortunate in this instance because 10k steps is widely regarded as a healthy target for activity levels.

Like a good iOS developer I’ve reported this to Apple as a bug (#15186313, if you work at Apple and can give it some love). But in the meantime I thought I was just plain stuck.

The API for setting the app’s badge only lets you show positive integers, so solutions using abbreviations like “10.2k” were out. This makes sense in general. I’m rather abusing this feature in a way that it isn’t really intended for. In situations where this value were huge and applied to the places it was intended for (Email, Messages, etc) when the value goes over 10,000 it isn’t really providing great value to the user. But in this case that is precisely when I need to show the value.

As with all great thoughts, while taking a shower I came up with an interesting alternative in the meantime. I got to wondering which values get truncated and which do not. It turned out that not all values greater than 10k get shortened, any number that happens to include two 1 digits is shown in full.

So that led me to the workaround solution that will be shipping in version 1.1.1. Whenever the step count gets over 10k I will change the step count to force it to include two 1s. For numbers between 10,000 and 19,999 this will be done by replacing the last digit with a 1. For values greater than 19,999 the last two digits will be replaced. Now the badge is never truncated. The loss in precision in the count is more than made up for by the ability to show the more significant digits at all.

I mention this process here because I thought it was an interesting example of working around an otherwise intractable issue. Usually a little bit of creative thinking can allow you to find someway around an OS constraint and deliver the user what they actually want.

Postscript: Step counts greater than 99,999 are still truncated but since taking 100k steps would require you to walk continuously for 24 hours averaging 1.2 steps per second that seems a reasonable limitation in practice.

David Smith