I call:
let existing = await FCM.getBadgeNumber()
await FCM.setBadgeNumber(existing+1)
When app is in foreground it increase badge icon by 1.
But if app is killed or in background badge number not increasing.
Where should I put this increasing functions in order to update badge number when notification arrive to phone when app is not oppened?
iOS or android?
Do you have listener outside of component lifecycle?
iOS it work when app is active but if in background or killed doesn't.
for iOS it won't work if app is killed by user. background process won't be waken up.
it should work in background though if you have "content_available:true"
This is payload:
{
"to":"ddd",
"notification":
{
"title":"test",
"body":"test",
"sound":"default",
"badge": 1
},
"data":{
"title":"test",
"body":"test",
"targetScreen":"DETAILS"
},
"priority":10}
And this is event:
export function registerAppListener() {
FCM.on(FCMEvent.Notification, async notif => {
let existing = await FCM.getBadgeNumber();
await FCM.setBadgeNumber(existing + 1);
I tried to add "content_available:true" but doesn;t work.
In foreground it work.
But when I press home button and send notification badge is not increment.
you tried like this?
{
"to":"ddd",
"notification":
{
"title":"test",
"body":"test",
"sound":"default",
"badge": 1
},
"data":{
"title":"test",
"body":"test",
"targetScreen":"DETAILS"
},
"content_available": true,
"priority":10}
Yes it's always 1
try remove "badge": 1
Tried that also
before we did deep, you need to know it is impossible to increment badge count if user force closed the app in iOS. Are you sure you want to go with this approach?
I didn鈥檛 close app completely.
I just pressed home and lock phone.
One more wierd thing happens on android when I press icon of the app I receive notification.
Openet from tray is 1 no title or body.
And on android it add badge whenever I press app icon.
when I press the icon of the app I receive notification.
this is expected. when you press the icon it has no knowledge of what notification it has. just ignore open_from_tray if there is no notification data
for iOS, can you add a breakpoint at https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L65 and see if it gets triggered?
_I will debug now.
I just tried with local notification and it is same. In example project I clicked schedule notification in 5 sec and pressed home button.
I get notification banner but no badge.
If I do the same in foreground send notification local 5 times and press home button icon has badge with 5 on icon.
So it's same with both types._
UPDATE
Actually issue is again present. When app is in background for about 10 minutes updating badge count again stop working. And now if I open app and put again to background it doesn't update badge anymore.
@evollu ignore my last two posts.
It actually work fine. But I would be thankful for explanation.
I removed completely registerKilledListener function even from import (actually even imported made a problem).
~~Problem is actually this code in this function:
FCM.on(FCMEvent.Notification, notif => {...
When I removed this putting app in background and sending notifications increment badge correctly.
Can you please explain me why this method exist and why do I wanted to have it?
_Also why registering notif callback in it made updating badges doesn't work?_~~
Ok it worked in the end and problem was with payload sent from server.
_Issue that I mention before pressing app icon increase badge count is not present anymore when I send custom_notification android badges update normally like on IOS._
So it seems it's necessary to send different payloads to both platforms.
Badges work correctly when payload for ios is:
{
"to": "r",
"notification": {
"title": "test",
"body": "test",
"sound": "default"
},
"data": {
"targetScreen": "details"
},
"content_available": true,
"priority": 10
}
and for android:
{
"to": "r",
"data": {
"custom_notification": {
"title": "test",
"body": "test",
"sound": "default",
"priority": "high",
"targetScreen": "details"
}
},
"priority": 10
}
cool