iOS Question Updating Badge Number

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am using Firebase Push notifications in my app and trying to add a number to the app icon as the push notification comes in to the device when the app is not open.

I am using B4J to send the message and looked on the forum and found that I need to use the following:

B4X:
Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default", "badge": 3)

This will add a 3 to the app icon.

I am then clearing the number as soon as the app opens by using:

B4X:
App.ApplicationIconBadgeNumber = 0

From what I have read on the forum, I need to set the badge number from my B4J app.

My aim is to add 1 to the app icon each time the push notification is received, and clear it when the app is open.

As I am clearing the badge number as soon as the user opens the app, my B4J app doesn't know what number to show on the app icon next time it sends the push notification.

What is the best way in telling my B4J app what number it needs to send when it sends the push notification ?

I am guessing if the app is not open it can't send anything to my B4J app to tell it that it received the push notification, so it can send a notification to update the number on the app icon ?

The push notifications are not unique to the user, so I am not aware of the user at the time of sending the notification and I am sending it to the topic in firebase and all devices registered to that topic get it.
 

aaronk

Well-Known Member
Licensed User
Longtime User
You must have a server for this that tracks the current number and is updated from the app when the badge is reset.
I understand that part as per my original post, but can't work out what the best way in doing this.

Let's say 2 users have my iOS app installed. Both subscribed to the topic 'General'.

I send a firebase message to the topic General. Both users get it and I set it as 1 on the app icon.

User 1 open the app and now I have cleared the number.
User 2 doesn't open the app.

I send the message again the second time (since my B4J app sends it as badge icon 2). Now it shows 2 for both users.

User 1 it should say 1 since they have already cleared it the once.
User 2 it should say 2 since they haven't opened the app.

How can I monitor this on my B4J server so it can send the badge number correctly based on the user ?
 
Upvote 0
Top