react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

Get onNotification triggered when a remote notification is received

Open rossicler-hostalky opened this issue 1 year ago • 2 comments

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

  • iOS: onNotification is called (this is working after changing AppDelegate.mm)
  • Android: onNotification is triggered

Background

  • iOS: onNotification is not called
  • Android: N/A

Killed/Closed

  • iOS: onNotification is not called
  • Android: N/A

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.

rossicler-hostalky avatar Jan 09 '24 19:01 rossicler-hostalky

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

ericowhadi avatar Feb 22 '24 14:02 ericowhadi

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.

ksetrin avatar Jun 28 '24 18:06 ksetrin