Push-Notification Badge auto increment

前端 未结 5 1144
囚心锁ツ
囚心锁ツ 2020-12-01 03:34

I\'ve been implementing the push service to my application, and I\'ve been thinking about the application\'s badge. My app is a mail app (sorta) and I want to notify the use

5条回答
  •  难免孤独
    2020-12-01 04:23

    It's sort of possible but there's a trade-off.

    You can always send up the unread total as an add-on JSON value as part of the push payload (push ignores keys it doesn't explicitly understand). Once the user opens the app, read the value and adjust the badge programmatically yourself via UIApplication's applicationIconBadgeNumber property.

    The problem with doing it that way is that push adjusts the badge value even if the user doesn't open the app (i.e. when they get the notice and the user hits 'Cancel' instead of 'View'). In those cases your badge won't change, but as soon as they run the app (if they hit 'View') then your app can set it right.

提交回复
热议问题