FCM onNotification only works when app is in background


#1

My Ionic 3 app receives notifications via the FCM plugin cordova-plugin-fcm (https://github.com/fechanique/cordova-plugin-fcm). I followed the example on the link, building for Android, testing on an emulator.

Here’s part of my onNotification()

FCMPlugin.onNotification(function(data){
        if(data.wasTapped){
          console.log("Received in background");
        } else {
          console.log("Received in foreground");
        };
      })

The issue is that it ONLY runs when you tap on the notification from the notification drawer while the app is in the background. So if the app is open and a notification arrives, the function doesn’t run. Basically, “Received in foreground” never fires, even when the app is in the foreground. I want “Received in foreground” to log as soon as a notification arrives, even before tapping it.

Any idea how I can accomplish this, please? Or am I missing something.