Search code examples
iosswiftpush-notificationfirebase-notifications

Firebase Push Notification Increase Badge Count When Receive Notification


I am using iOS 10 with swift 2.3 I need to increase badge count when receiving new notification from firebase. I have code to increase badge count

let badgeCount: Int = BadgeCount + 1
UIApplication.sharedApplication().applicationIconBadgeNumber = badgeCount

But I don't know where to use it to make it work correctly.


Solution

  • If you are using push notification, then you cannot maintain the count from your app. You need to write this logic server side because your app will not come to know about push until and unless user taps on it. Second option is using silent notifications. Silent notifications are delivered to your app and then you need to trigger local push and maintain the badge count. Disadvantage of silent notification is, you won't receive silent notification if user kills your app.