Add badge to your iOS App

Adding badge to an app is fancy. You can directly look at the icon and verify the badge number assigned to the app. This could be your number of unread emails, points or even the time it takes for your ride to come to your place.

I am going to demonstrate it with simple example project. The project is simple. You have list of messages displayed in tableView. They are all initially unread. You can click them so as to mark them unread. Once it updates the number of unread messages, it will also update the badge counter on the home page.

Remember that app does not persist the number of read/unread messages, but it will reset the counter between launches.

Adding badges is very easy task. In the following paragraphs I will demonstrate step by step how you can perform this action:

  • Asking user permission to add badge to app icon

First important thing you will have to do is asking a user permission. I am assuming you all are on iOS8+. So the code for registering to user notification setting only applies to iOS8+.

You will have to ask this permission only once. However, user can modify these permissions by going into application setting

Asking user permission to show badge on the springboard


let types: UIUserNotificationType = UIUserNotificationType.Badge 
let notificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)

Make sure you put this code in
Appdelegate file and preferably execute this routine in


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 

method as soon as application finishes launch

  • Now say you have a list of messages. (Let's say in the beginning they are all unread). So app badge on home page will show this unread count. Now you click on one of the messages, which causes that message to switch to read state.

    To get the better idea, I have this following routine which takes the input parameter as input to increase badge counter by and increases it accordingly.


func incrementBadgeNumberBy(badgeNumberIncrement: Int) {
        let currentBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber
        let updatedBadgeNumber = currentBadgeNumber + badgeNumberIncrement
        if (updatedBadgeNumber > -1) {
            UIApplication.sharedApplication().applicationIconBadgeNumber = updatedBadgeNumber
        }
    }

The reason I put a check for if (updatedBadgeNumber > -1) is badge number has no effect on icon when badge number count goes below 0.

Demo Project

I have also created a demo project on GitHub to Demonstrate the usage of badge counter to iOS app.

Summary of the project

  1. App presents list of messages as if they are downloaded from web API
  2. All the messages are unread first, so the badge counter on app icon is equal to number of message
  3. As user reads messages, it reduces this count by 1, calculate new number of unread messages and set this count as a badge number for an application
  4. This unread count is not stored persistently. It resets on every app launch