0

On android, when you have pending notifications, the icon of the app will display a circle for telling the user that pending notifications exists for the app, you don't need to implement anything or adding code to the app. On iOS I see that some apps display that circle, even including a number of pending notifications. How can that be implemented? I can't find any official documentation about that.

The only think I can find is this: https://github.com/ionic-team/capacitor/issues/1301

There, an answer says that on IOS you need to include this playload:

iOS differs from Android with regards to the badge-count. While on Android it is directly connected to the number of unhandled recieved notifications on iOS it's dependent upon what you yourself set it to.

You need to include the badge-count in the payload:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9
    }
}

Where whould be included that playload? And which code whould be added in swift inside the ios application to display the badge with the number of pending notifications?

NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • [Here](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification) is the documentation. And you have to set the badge in code with [`applicationIconBadgeNumber`](https://developer.apple.com/documentation/uikit/uiapplication/1622918-applicationiconbadgenumber) – vadian Mar 31 '22 at 08:45
  • @vadian thank you very much, so it is necessary to add code, but in the second link you provide, they talk only about a function called "applicationIconBadgeNumber" but they don't explain where should I use that function and how should I use it. – NullPointerException Mar 31 '22 at 08:49
  • It's supposed to be called on the shared instance of the application `UIApplication.shared.applicationIconBadgeNumber = 9`. And make sure that's being called on the main thread. – vadian Mar 31 '22 at 08:51
  • @vadian I don't understand you. Does apple provide a guide of how to use this function? I don't know what you mean with shared instance of the application, and where are you getting that "9"? – NullPointerException Mar 31 '22 at 08:53
  • Here is the documentation about the User Notification Framework: https://developer.apple.com/documentation/usernotifications/. And please search for Apple Push Notifications or APNS. There are a lot of tutorials. – vadian Mar 31 '22 at 09:01

0 Answers0