Get onNotification triggered when a remote notification is received

Author: rossicler-hostalkyCreated Jan 9, 2024Updated Oct 23, 2024

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.

Source: zo0r/react-native-push-notification