Problem solved. I was making it unnecessarily complicated.
Reliable process (tested on android):
- Remove
content-availablein payload to avoid duplicate notification callback mess - In
on('notification')the following set of conditions means you tapped on a notification - works for app in background or killed
if (data.additionalData.foreground == false &&
(data.additionalData.dismissed != undefined ||
data.additionalData.coldstart == true))
{
// user tapped on notification
}
- Remember that ‘notification’ handler can be called anytime after your app has finished initing - there is no guarantee the callback will be invoked at a particular time relative to the rest of the app bootstrap - its an async event and there are no guarantees on how long it takes to get called with respect to the rest of the state of your app. This is where I was messing up. So I am emitting an event here so its handled whenever it is called