question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: (messaging) `notificationReceived` fires only for the last message received while the app is killed

See original GitHub issue

Plugin(s):

@capacitor-firebase/messaging”: “^1.1.0”

Platform(s):

Android

Current behavior:

If a data-only notification is received while the app is killed or the device is in doze, the notficationRecieved listener event does not fire. When the app is opened the next time, the listener fires only for the last message recieved while the app was killed. Every other message is dropped.

Expected behavior:

Code given to the listener should be executed regardless of doze or killed app. Documentation states If the app is in the background, then this listener is only called on data push notifications., but does not make any statement about the app being killed.

Steps to reproduce:

Add listener and send data-only notification to device while app is killed:

    FirebaseMessaging.addListener('notificationReceived', event => {
      console.log("Notification recieved: ", event);    //fires if message is recieved while app in foreground or background
      if(event.notification.data?.payload){                  //but not if app is killed
        //do something traceable which doesn't need console
        //for example, write a small file with messageid as filename
      }
    });

message:

        token: "notificationtoken",
        data: {
          payload: "messagePayload"
        },
        android: {
          priority: "high"
        }

Capacitor doctor:

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/ios: 4.3.0

Installed Dependencies:

  @capacitor/cli: 4.1.0
  @capacitor/core: 4.2.0
  @capacitor/ios: 4.2.0
  @capacitor/android: 4.2.0

[success] Android looking great! 👌

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
crowbaitcommented, Oct 2, 2022

This might be a bit off-topic, but for anyone passing here on the hunt for a solution to my problem, adding your own FirebaseMessagingService extender doesn’t play well with capacitor either. I’ve written about that here: https://github.com/ionic-team/capacitor-plugins/issues/1211#issue-1393872221

0reactions
crowbaitcommented, Oct 2, 2022

Just for the sake of being thorough: I just tested the behavior in a production (non-debug) app via internal testing track on google play.

  • messages before the most recent one still get dropped when the app opens
  • data-messages don’t get handled if the app has been swiped (“closed”) from recent apps tray; should be passed to listener on next app launch then

I did this test because I learned that push notifications allegedly have different behavior in debug vs production and also Android is said to kill services associated with an app on close if the app is debug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase onMessageReceived not called when app in ...
This is working as intended, notification messages are delivered to your onMessageReceived callback only when your app is in the foreground.
Read more >
onMessageRecieved not working when app is killed. #368
onMessageRecieved not working when app is killed. It works perfect in foreground and in background and I can receive Extras in MainActivity.
Read more >
The Push Notifications Guide for Ionic & Capacitor
To send push notifications to your users with Ionic and Capacitor you don't need a specific service, but you need to configure a...
Read more >
The Last Message Received
A Tumblr run by a 21-year-old containing submissions of the last messages people received from ex-friends or ex-significant others, ...
Read more >
Firebase Push Notification in Ionic React app using Capacitor
Learn how to implement firebase push notifications in Ionic-React apps using ... as it fires when you tap the notification received when the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found