Hi this is Marin - the author of Touch Code Magazine, I hope you are enjoying my tutorials and articles. Also if you need a bright iPhone developer overseas contact me - I do contract work. Here's my LinkedIn profile
How to add a badge to the application icon

You’ve seen many times the Mail icon on your home screen featuring a red badge with the unread message you currently have in your Inbox. That’s really cool effect while you can effectively keep track of this number without having to start the app to check it. Now in your own app this number might be something else – unread RSS items, unanswered chat messages, or for example might be something totally different (not necessarily useful) – for example the days since your app was installed on the device – how about that?

Anyhow – putting the badge on the icon is really easy.

Put this number on that icon

Since iOS4 the UIApplication class has a property called applicationIconBadgeNumber. You can assign any integer to that property, although my test show that if you assign anything less than 1 (ie zero or negative integers) there just won’t be any badge on your icon. (NB: pay attention only iOS4 solution)

Here’s a short example code how to set the number on the badge:

Example app

You can download my example XCode project and play with it to check for yourself how the badges look like. The demo app will show you the current badge number with couple of buttons to increase and decrease that number. When you change the number, quit the app and have a look at the app icon- nice!

Download badge test project source code here

The post was originally published on the following URL: http://www.touch-code-magazine.com/how-to-add-a-badge-to-the-application-icon/




Marin Todorov

is an independent iOS developer and publisher. He's got more than 18 years of experience in a dozen of languages and platforms. This is his writing project.
» Contact    » Add Marin on Google+