Andrei Andrei - 5 months ago 45
Android Question

react-native push notification onNotification doesn't trigger

I am using zo0r react-native-push-notification library.

"react": "16.0.0-alpha.12",
"react-native": "^0.45.1",
"react-native-push-notification": "^3.0.0"

This code runs every time I open an app:

onNotification: function(notification) {
console.log('onNotification');'onNotification', 3000);

I send local push notification from background service:

message: 'Hello World',
smallIcon: 'ic_launcher'

The notification gets delivered. When I click it,
method doesn't get called, then when I receive another notification, it actually gets called. It seems like it works only if app is in memory atm.

Am I doing something wrong?

I have opened a GitHub issue as well.

Answer Source

In my code I configured notifications outside App class - that was an issue. I just moved the configuration to App constructor and now it works just fine, onNotification gets called with no problem:

class App extends React.Component {
    constructor(props) {
        PushNotification.configure({ ... });