Ionic 4 problem managing push notifications when the app is closed or in background

The notifications are not triggering the push.on(‘notification’) when the user taps on the notification and the app are closed or in the background.

I have this code been initialized on platform.ready()

import { Push, PushObject, PushOptions } from ‘@ionic-native/push/ngx’;

……

// to check if we have permission
this.push.hasPermission().then((res: any) => {
  if (res.isEnabled) {
    console.log('We have permission to send push notifications');
  } else {
    console.log('We do not have permission to send push notifications');
  }
});

// Create a channel (Android O and above). You'll need to provide the id, description and importance properties.
this.push.createChannel({
  id: 'testchannel1',
  description: 'My first test channel',
  // The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
  importance: 3
}).then(() => console.log('Channel created'));

// Delete a channel (Android O and above)
// this.push.deleteChannel('testchannel1').then(() => console.log('Channel deleted'));

// Return a list of currently configured channels
this.push.listChannels().then((channels) => console.log('List of channels', channels))

// to initialize push notifications

const options: PushOptions = {
  android: {},
  ios: {
    alert: 'true',
    badge: true,
    sound: 'false'
  },
  windows: {},
  browser: {
    pushServiceURL: 'http://push.api.phonegap.com/v1/push'
  }
};

const pushObject: PushObject = this.push.init(options);

pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));

The pushObject.on(‘notification’) is triggered if the app is open but it should also trigger on the tap on the notification if the app is closed/background.

IONIC INFO:

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.2.0
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.1.4
   @angular/cli                  : 7.1.4
   @ionic/angular-toolkit        : 1.2.2

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic 5.3.0, cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 21 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/tdonatti/Library/Android/sdk)
   ios-deploy        : 1.9.2
   ios-sim           : 5.0.13
   NodeJS            : v11.6.0 (/usr/local/bin/node)
   npm               : 6.5.0-next.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001

> cordova plugin ls
cordova-android-firebase-gradle-release 2.1.0 "cordova-android-firebase-gradle-release"
cordova-android-play-services-gradle-release 2.1.0 "cordova-android-play-services-gradle-release"
cordova-android-support-gradle-release 2.1.0 "cordova-android-support-gradle-release"
cordova-plugin-add-swift-support 1.7.2 "AddSwiftSupport"
cordova-plugin-buildinfo 2.0.2 "BuildInfo"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-facebook4 4.2.1 "Facebook Connect"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-firebase-analytics 0.13.0 "FirebaseAnalyticsPlugin"
cordova-plugin-firebase-dynamiclinks 0.13.2 "FirebaseDynamicLinksPlugin"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-intercom 6.2.0 "Intercom"
cordova-plugin-ionic 5.3.0 "cordova-plugin-ionic"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.0.1 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-vibration 3.1.0 "Vibration"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-sqlite-storage 2.6.0 "Cordova sqlite storage plugin"
cordova-support-google-services 1.1.0 "cordova-support-google-services"
ionic-plugin-deeplinks 1.0.19 "Ionic Deeplink Plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-multidex 1.0.0 "Multidex"
phonegap-plugin-push 2.2.3 "PushPlugin"

Still looking for solutions for this. Any help?

I am a little late to the party but you need to have the payload of your push notification to be in a specific format Check this out to get a better idea

It has to be in this format

{
  "data": {
    "title": "Test Notification",
    "body": "This offer expires at 11:30 or whatever",
    "notId": 10,
    "youData": "foo"
  }
}