React-native-push-notification: onNotification() is not fired when app is in background.

Created on 20 Feb 2018  路  8Comments  路  Source: zo0r/react-native-push-notification

I am able to get logs on the console from onNotification() method when app is open (in foreground), but not getting any when app is closed (not killed).

Here is my code -

PushNotification.configure({
            // (required) Called when a remote or local notification is opened or received
            onNotification: function (notification) {
                console.log(notification);
            },
            // IOS ONLY (optional): default: all - Permissions to register.
            permissions: {
                alert: true,
                badge: true,
                sound: true
            },
            // Should the initial notification be popped automatically
            // default: true
            popInitialNotification: true,
            /**
.....

Most helpful comment

React Native Push Notifications clearly states that we need to call configure outside of the React Native Lifecycle. This is very important.

https://product.farewell.io/visible-react-native-push-notifications-that-work-on-both-ios-and-android-5e90badb4a0f

https://prnt.sc/k61hz7

All 8 comments

it not supposed to be in the component tree, hope that helps.

same problem

@atebit Unable to understand what your wrote. Should we place PushNotification.configure() outside of the component

This might be helpful.

React Native Push Notifications clearly states that we need to call configure outside of the React Native Lifecycle. This is very important.

https://product.farewell.io/visible-react-native-push-notifications-that-work-on-both-ios-and-android-5e90badb4a0f

https://prnt.sc/k61hz7

Having the same issue, @kckunal2612 any workaround?

Do not put PushNotification.configure inside of a React.Component, it must be outside of the React rendering lifecycle. If you put the PushNotification.configure on your index.js file and a console.log, you will see it working.

This can be closed as it's not an issue...

@atebit why is this the way it is? I need to navigate and do react things in the onNotification() call back.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kiran0791 picture Kiran0791  路  3Comments

anativ picture anativ  路  3Comments

Benzer1406 picture Benzer1406  路  3Comments

selimonline picture selimonline  路  3Comments

uendar picture uendar  路  3Comments