iOS Question Push notification not updating app icon badge number

biometrics

Active Member
Licensed User
Longtime User
Following on from my thread to get push notification working when the app is in the background: https://www.b4x.com/android/forum/t...n-only-works-when-app-is-in-foreground.82928/

When I get the notification the app icon badge number is not increased. Should that not happen automatically?

I tried to use background fetch (https://www.b4x.com/android/forum/threads/background-fetch-downloads.56022) to update the badge number using:

B4X:
App.ApplicationIconBadgeNumber = 123

But the Application_FetchDownload event never fires.

So how do I update the app icon badge number when the app is in the background or is the OS supposed to do it? Maybe I need to send something else when I send the JSON to fcm.googleapis.com/fcm/send?
 

biometrics

Active Member
Licensed User
Longtime User
No.
The badge value should be included in the JSON message. If you are using the B4J tool to send the messages then add it here:
B4X:
Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default", "badge": 3)

I've added "badge" to the JSON and it's working now. Of course it doesn't increase with each notification so for now I'm cheating and sending a "1". At least it shows a badge rather than none though it may not be the right number. In the use case of this app it will be correct most of the time. ;)
 
Upvote 0
Top