evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 682 forks source link

What to do when the app is dead? #970

Open rochapablo opened 6 years ago

rochapablo commented 6 years ago

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
fecabianchi commented 6 years ago

i'm facing the same issue, any light @evollu ?

faysal515 commented 6 years ago

@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/

fecabianchi commented 6 years ago

@faysal515 i see that you are sending the badge value from the backend right? how do you control the badge value?

faysal515 commented 6 years ago

@fecabianchi we're maintaining this information in the server. once the app is being opened, we're clearing the badge counter to 0

evollu commented 6 years ago

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

fecabianchi commented 6 years ago

@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?

faysal515 commented 6 years ago

@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.

  1. whenever we're sending notifications to a specific user only, we're incrementing a value lets say badge in the server. sending the badge in the notification payload
  2. 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 badge value to be 0 for that user.
fukemy commented 2 years ago

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