React-native-push-notification: onMessage not fired when app inactive/killed.

Created on 21 Sep 2020  路  6Comments  路  Source: zo0r/react-native-push-notification

Hello,

Platform Android.

I want to catch info from notification but onNotification passed in .configure(object) is fired only when application is in foreground. Also tried
PushNotification.popInitialNotification((notification) => console.log('InitialNotication:', notification)); but in this case I get 'undefined'.
Also if someone knows something about how to show banner on main screen.

"react": "16.13.1", "react-native": "0.63.2", "react-native-push-notification": "^5.1.1",

Most helpful comment

You will probably find the solution issues, this is probably related to a splashscreen which intercept the notification.

All 6 comments

DO NOT USE .configure() INSIDE A COMPONENT, EVEN App

If you do, notification handlers will not fire, because they are not loaded. Instead, use .configure() in the app's first file, usually index.js.

I've read this and tried to call it in various files including App.js componentDidMount, helper index.js and ofc app's first file still get same result. Also tried with your example and got same result.

Hi,

You must put this outside of a component. componentDidMount is a part of the component

@Dallas62 this is my index.js file

`
import { AppRegistry } from 'react-native';
import PushNotification from 'react-native-push-notification';
import App from './App';
import { name as appName } from './app.json';

PushNotification.configure({
onRegister(token) {
console.log('token: ', token)
PushNotification.popInitialNotification(function (notification) {
console.log('popInitialNotification', notification)
});
},
onNotification(notification) {
console.log('notification', notification)
// iOS only
// notification.finish(PushNotificationIOS.FetchResult.NoData);
},

senderID: "someid",
requestPermissions: true,

});

AppRegistry.registerComponent(appName, () => App);`

You will probably find the solution issues, this is probably related to a splashscreen which intercept the notification.

Ok so when you use react-native-splash-screen it brakes chain and do not pass notification data into main activity on android. So the solution is here https://github.com/crazycodeboy/react-native-splash-screen/issues/289#issuecomment-421537284.
Closing issue.

Was this page helpful?
0 / 5 - 0 ratings