question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Method to catch notification clicked event?

See original GitHub issue

When APP run both in foreground and background, I know notification is clicked in onNotification. When I kill APP first and click notification, APP start running but onNotification is not triggered. Is there method getting the notification clicked event?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:19

github_iconTop GitHub Comments

6reactions
valeryqcommented, Jul 25, 2017

@shrutic @JonoH hello guys. You must manually invoke the PushNotification.popInitialNotification(notification => YOU_HANDLER(notification)) each time when application started. For example in your root component in componentDidMount.

In my case, I invoking popInitialNotification one time, when application state is changed to active and remove listener for this event.

Example:

const appStateListener = (state) => {
  if (state === 'active') {
    AppState.removeEventListener('change', appStateListener);
    PushNotification.popInitialNotification(notification => notification && onNotification(notification));
  }
};

AppState.addEventListener('change', appStateListener);
3reactions
JonoHcommented, Jul 25, 2017

@valeryq that works!!! Thanks so much! I’m now receiving the notification in the onNotification handler once I click on the notification (regardless of app state). Lifesaver!!

This needs to make it into the documentation as many people seem to be struggling with this exact issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notification: click event - Web APIs - MDN Web Docs - Mozilla
The click event of the Notification interface fires when the user clicks on displayed Notification.
Read more >
Get click event on Notification - android - Stack Overflow
I have a notification that opens a url. So far, so good. Now I need to do some things when the notification is...
Read more >
SDK Notification Event Handlers - OneSignal Documentation
OneSignal SDK setNotificationOpenedHandler method runs upon opening the app after a notification is clicked. Background Notification Received Event, Native ...
Read more >
Handling Notifications and Notification-Related Actions
Handle User-Selected Actions. Actionable notifications let the user respond to a notification directly from the notification interface.
Read more >
Notification behavior - web.dev
As you can see in this example, the notification that was clicked can be accessed as event.notification . From this, you can access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found