zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.75k stars 2.05k forks source link

Get onNotification triggered when a remote notification is received #2402

Open rossicler-hostalky opened 8 months ago

rossicler-hostalky commented 8 months ago

Question

Is it possible to make onNotification listener to run every time my app receives a remote notification?

Currently this behaviour is the behaviour for each app state:

Foreground

Background

Killed/Closed

So, I wanted that onNotification would be called for every remote notification received, doesn't matter the app state. After reading some issues in the repository and some posts on stack overflow, it seems to be possible, but I'm not sure. If anyone have some idea how to achieve this, please let me know.

My goal is to receive remote notifications, but never show remote notifications to the user, and once onNotification is called, send a localNotification instead.

ericowhadi commented 7 months ago

the reason you are not receiving notification in background or killed is because you are doing the pushNotification.configure after the AppRegistry.registerComponent(appName,()=>App) (ie in App.js). If you do it in index.js, you should receive the notification in all states. It works for me...

ksetrin commented 3 months ago

the reason you are not receiving notification in background or killed is because you are doing the pushNotification.configure after the AppRegistry.registerComponent(appName,()=>App) (ie in App.js). If you do it in index.js, you should receive the notification in all states. It works for me...

I can't believe it!

But it's really a solution! I tried everything I could to find a solution, but it's so simple!

I don't understand why there is no mention of it in the documentation and README? How could they forget to mention such an important factor?

It's unbelievable.