0

iOS 8 or 9

When I get push notification in my iOS app I want to update the badge number (count in red) shown on the app icon without opening the app.

Currently it gets updated only and only once the app is opened.

Is that possible?

Gaurang
  • 65
  • 2
  • 12

1 Answers1

7

You need to set a value for the badge key in your push notification payload. Payload Notification

The payload contains information about how you want to notify the user, such as using an alert, badge or sound. It can also contain custom data that you define.

To remove the badge, set the value of this property to 0.

Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
  • I have already passed count in "badge" key in payload. Do i need to do anything at app end? Thank you. – Gaurang Jan 09 '16 at 13:00
  • You just need to set 0 count – Mayank Patel Jan 09 '16 at 13:01
  • I am setting the count as number. Let's say 5. Then as soon as push notification comes badge number should be changed to 5 right? But it's not happening so – Gaurang Jan 12 '16 at 04:44
  • @Gaurang you can set badge count 0 in `didReceiveRemoteNotification` or in payload you can set to 0 got it ? just refer the link the which i post in answer – Mayank Patel Jan 12 '16 at 04:46
  • Thank you very much Mayank, actually I was passing in badge only but as it was coming through database it was in form of STRING. iOS app requires it in form of INT. I just did 'badge' => (int)$unreadCount and it's done !! – Gaurang Jan 16 '16 at 12:54
  • happy to help!.. g8 @Gaurang – Mayank Patel Jan 18 '16 at 03:43
  • Is it possible to do the same on Android? – Dima Jan 23 '20 at 10:02
  • But how then? I have tried different approaches, but nothing works. I use Microsoft's AppCenter to send my notifications. – Dima Jan 23 '20 at 10:32