ionic 3: in android fcm.onNotification() not getting called on clicking the notification when the app is in background

781 views Asked by At

In my ionic 3 app i am using cordova-plugin-fcm-with-dependecy-updated everything working fine except 1 case.

If the app is killed and when clicking on notification then onNotification() no getting called but it's getting called if the app is open.

I have check few posts but none of them worked for me :

Previously, I was using cordova-plugin-fcm-with-dependency-updated-apns which was working perfectly but due to UIWebView Deprecation in IOS, I need to use another option.

Here is my server payload :

    {
    "to" : "FCM_Token",
    
  "notification":{
    "title":"Notification title",
    "body":"Notification body",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY"
  },
  "data":{
    "param1":"w1",
    "param2":"w1"
  },
  "priority":"high"
}

I am using cordova: 10.0.0 / ionic: 3.9.2 / cordova-ios: 6.1.1 / cordova-android: 9.0.0

Anyone has an idea of how I can get onNotification() called when clicking on it if the app is killed.?

2

There are 2 answers

1
Reqven On

I've been using this Firebase Messaging plugin for a while now and it works great.
It's actually the featured plugin in the Ionic documentation .

ionic cordova plugin add cordova-plugin-firebase-messaging
npm install @ionic-native/firebase-messaging

It offers a different method for notifications received in the background.
You should definitely try it out.

onMessage(callback)
Called when a push message received while app is in foreground.

onBackgroundMessage(callback)
Called when a push message received while app is in background.

0
Wasim On

There is no clear solution so I ended up moving to onesingle. They provide unlimited push notification for mobile in the free plan. I tried and it's working great!