Determinate whether push notification was just received or tapped on

Hello!

The event listener that’s added through

Runtime:addEventListener("notification", notificationListener)

is run at many different occasions:

  • App was inactive and the user clicked on the notification
  • App was running and the event listener is automatically run when the event is recieved
  • App was running and the user clicked on the notification
  • App was completely shut down and the user clicked a notification (if manually run on startup like you recommend)

It’s of course great that you can interact with the event at several stages, but my problem is that it is impossible to differentiate the second and third event listeners. In both cases e.applicationState == “active”. Is there something that I am missing or is it really impossible to see the difference?

I need this feature because when a user taps on the notification I want to send them to a specific scene, but I don’t want to send them there automatically if they would happen to get a notification whilst doing something else.

Edit: This is how it works on Android, might differ slightly on iOS since I haven’t tested that as throughly yet.

1.  App suspended in background, user interacts with push:

The app is foregrounded.  The notification listener is triggered.  You should also get an application resumed event as well.

  1. The app is running when the notification arrives.

The notification listener is triggered.  No resume event.

  1. The app was running and the user interacted with the notification.

I’m not sure this can happen.  The app should just get a notifications event like #2 above and your app is responsible for displaying the notifications.

4a. The app was shut down completely and the user interacted with the push notification.

In this case launchArgs will be set with the notification information and you can check for the presence of the notification in the launchArgs to detect this

4b. The app was completely shutdown and the user start’s it without interacting with the push notification.

Your app will know nothing about the received push notification.

Rob

1.  App suspended in background, user interacts with push:

The app is foregrounded.  The notification listener is triggered.  You should also get an application resumed event as well.

  1. The app is running when the notification arrives.

The notification listener is triggered.  No resume event.

  1. The app was running and the user interacted with the notification.

I’m not sure this can happen.  The app should just get a notifications event like #2 above and your app is responsible for displaying the notifications.

4a. The app was shut down completely and the user interacted with the push notification.

In this case launchArgs will be set with the notification information and you can check for the presence of the notification in the launchArgs to detect this

4b. The app was completely shutdown and the user start’s it without interacting with the push notification.

Your app will know nothing about the received push notification.

Rob