What to do when the app is dead?
Hey, this is more a question; The notification it's working pretty well while the app is opened (foreground) and minimized (background); events and badge working. Good.
Now problem is, while the app is dead (closed) I can only receive those banners, but not badge or listeners; Question:
Is there a way to fix this? Should I use react-native-fcm or native code?
What version of RN and react-native-fcm are you running?
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-fcm": "^15.0.0",
What device are you using? (e.g iOS9 emulator, Android 6 device)?
iPhone 6 - iOS11
Is your app running in foreground, background or not running?
Running in foreground and background
NOT Running when id dead/close
i'm facing the same issue, any light @evollu ?
@rochapablo @fecabianchi faced this exact same issue few days ago. Took a chance to write it as a blog post, take a look
http://faysal515.xyz/2018/06/react-native-push-notifications-counter-implementation/
@faysal515 i see that you are sending the badge value from the backend right? how do you control the badge value?
@fecabianchi we're maintaining this information in the server. once the app is being opened, we're clearing the badge counter to 0
I'm doing the same as @faysal515
back to @rochapablo 's question.
when you say while the app is dead (closed), do you mean you swiped and killed the app? In that case, no logic will be triggered (JS or native code). however, badge should still be updated if you put it in notification payload
@faysal515 where do you put the code for clearing the badge? when the app is dead and i open the app my event that set the badge to 0 is not triggered... when you clear the badge you update the database?
@fecabianchiI don't exactly know where is our setting badge to 0 is written since someone else on our team is working on the react native part. But most probably in the componentDidMount of the root component. And yes, we're also clearing db at that time. I'm writing the process if that somehow helps you.
- whenever we're sending notifications to a specific user only, we're incrementing a value lets say
badgein the server. sending thebadgein the notification payload - as soon as the user opens the app, we're setting badge to 0 in the device and also requesting our server to update the
badgevalue to be 0 for that user.
i tested with android when app totally closed. I got this function triggered:
messaging().onNotificationOpenedApp(remoteMessage => {
console.log('Notification caused app to open from background state:', remoteMessage)
})
But when user click into notification, app opened without any callback, then i can not get message data