Hello,
i can receive notifications while in background/foreground and if the user taps the notification the onNotification is called. But, if the app is killed, when the user taps the notification received, the apps opens but onNotification is never called. Nothing happens.
What i need to do? help!
// **App.js file**
import { configurePushNotifications } from './src/configuration/NotificationService';
...
configurePushNotifications();
export default class App extends Component {
render() {
return (
<Provider store={store}>
<AppContainer
ref={(navigatorRef) => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
// persistenceKey={navigationPersistenceKey}
/>
<PushController />
</Provider>
);
}
}
...
**// NotificationService - file**
export const configurePushNotifications = () => {
PushNotification.configure({
async onRegister(notificationTokenObject) {
sendNotificationTokenToServer(notificationTokenObject.token, notificationTokenObject.os);
},
onNotification(notification) {
onNotification(notification);
},
senderID: '',
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
};
let onNotification = (notification) => {
if (!!notification.title && !!notification.body) {
PushNotification.localNotification({
title: notification.title,
message: notification.body,
});
}
};
**//PushController.js file**
...
componentDidMount() {
setCallbacks(this.onNotification, this.popInitialNotification);
}
onNotification = (notification) => {
if (notification.userInteraction) {
NavigationService.openArticleFromNotification(notification);
}
if (notification.foreground) {
this.props.showNotification(notification);
} else {
PushNotification.localNotification({
title: notification.title,
message: notification.body,
});
}
};
@TfADrama For me it worked when using - called after configuring PushNotification framework, when opening the app:
PushNotification.popInitialNotification((notification) => {
Console.log(notification);
})
@TfADrama For me it worked when using - called after configuring PushNotification framework, when opening the app:
PushNotification.popInitialNotification((notification) => { Console.log(notification); })
Now it's working, in my code i put the 'popInitialNotification' on componentDidMount of my push controller and deleted everything that i have about popInitialNotification. So it ended like this:
**//PushController.js file**
...
componentDidMount() {
if (Platform.OS === 'android') {
PushNotification.popInitialNotification((notification) => {
if (notification) {
/* do things with the notification */
}
});
}
setCallbacks(this.onNotification);
}
onNotification = (notification) => {
if (notification.userInteraction) {
NavigationService.openArticleFromNotification(notification);
}
if (notification.foreground) {
this.props.showNotification(notification);
} else {
PushNotification.localNotification({
title: notification.title,
message: notification.body,
});
}
};
Now i have a funny behaviour, when the app is closed and i received a notification, the popInitialNotification is executed. After this, if i close the app again and receive another notification, it will be called both onNotification and popInitialNotification.
It happened with you @claudiumatei ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
@TfADrama For me it worked when using - called after configuring PushNotification framework, when opening the app:
PushNotification.popInitialNotification((notification) => { Console.log(notification); })