react-native-push-notification: Callback not triggered when notification is opened and app is killed

I’m having an issue with the onNotification callback not being called if the app is killed and the notification is clicked. Is there anyway to implement this functionality in the app?

RN -> 0.30.0 react-native-push-notification -> 2.0.2

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 16
  • Comments: 37 (4 by maintainers)

Most upvoted comments

Ok, so I managed to work around the issue. However, I’m running a version behind you guys, but it might still work for you. RN -> 0.29.0 react-native-push-notification -> 2.0.1

PushNotification.configure({ 
      onRegister: (response) => this.onRegister(response.token),
      onNotification: (notification) => this.handleNotification(notification),
      popInitialNotification: false, 
      ...
})

And in my onRegister method, I did:

onRegister(token) {
      PushNotification.popInitialNotification((notification) => {
            if (notification) { this.handleNotification(notification); }
      });
      ...
}
PushNotification.localNotificationSchedule({
 message: "My Notification Message", // (required)
 date: new Date(Date.now() + (10 * 1000)) // in 10 secs
});

@jakkra this solution still works in 3.0.2 (Android), however popInitialNotification needs to called from the UI (a component) rather than onRegister event handler

same here

@Mura7 There is an issue react-native-community/push-notification-ios#106 on addEventListener. The library is a simple proxy for this part, and doesn’t include iOS specific implementation: index.js#L84

this.callNative( 'addEventListener', [ 'notification', this._onNotification ] );

Any final solution for @japesh trick ?

Edit: Even with your hack, my onNotification is never called when my app is in background or killed.