简体   繁体   中英

Update push notification badge count

I am stating to implement push notifications in my app and have a question about the badge count. I would like my app to behave like email and other apps, such that every time an alert is received the badge count number increments.

Since the badge count number is part of the payload, what is the best way to have it increment?

When I send my first notification with the message and badge number, what do I do on subsequent notifications? Do I need to store all the notifications I send?

Any clarification on this would be most helpful.

Thanks for the help!

如果要增加该数字,则必须在服务器上跟踪该数字,没有其他方法。

This one really depends on what the notifications are for. If its for a news app and you are pushing breaking news it'll be quite difficult to increment the badge properly. Where as if it a game app and you are pushing to tell the player its their turn it would be much easier.

Examples (Psuedo):

News App

  1. Article Posted

    1.1 Push Sent

    1.2 Added to a database of pushes including who it was sent to, check database for other pushes to the same user, sees no previous push, BADGE = 1.

  2. App is Opened

    2.1 Badge goes back to 0, tells database to delete all pushes for that device/user/ BADGE = 0

  3. Article Posted

    3.1 Push Sent

    3.2 Added to a database of pushes including who it was sent to, check database for other pushes to the same user, sees no previous push, BADGE = 1.

  4. Article Posted

    4.1. Added to a database of pushes including who it was sent to, check database for other pushes to the same user, sees previous push, BADGE = 2.

  5. App is Opened

    5.1 Badge goes back to 0, tells database to delete the pushes for that device/user. BADGE = 0

Game App

  1. Player 2 Goes
  2. Push to Player 1, check database to see if it is Player 1's turn in any other game, BADGE = Count of games where its P1's turn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM