setBackgroundMessageHandler is not called in terminated state

Viewed 2235

I use firebase/messaging in my react-native application to receive data-only notifications from firebase.

When a message is received, i'll process the data, update my state and show a local notification with react-native-push-notification if the app is in background or terminated.

messaging().setBackgroundMessageHandler(async remoteMessage => {
  PushNotification.localNotification({...})
})

At the android device everything works perfect in foreground, background and terminated state.

In iOS foreground and background is working.

When the app is terminated i can log the notification in the console (see below) AND there is a notification sound. But no local notification is showing up.

When i try to logg the iOS device the console prints following output

default 03:51:53.697535+0100 dasd Daemon Canceling Activities: {(
    com.apple.pushLaunch.de.myapp.app:D1FAA2
)}
default 03:51:53.697770+0100 dasd CANCELED: com.apple.pushLaunch.de.myapp.app:D1FAA2 at priority 10 <private>!

My message from the server is:

const message = {
      data: {
        body: JSON.stringify(msgBody),
        title: title,
      },
      contentAvailable: true,
      priority: "high",
      android: {
        priority: "high",
      },
      apns: {
        headers: {
          "apns-priority": "10",
          "apns-push-type": "alert", //already tried background too
          "apns-topic": "de.myapp.app",
        },
        payload: { aps: { sound: "default", contentAvailable: true } },
      },
 
      tokens: userTokens,
    };

It drives me crazy for days now and i cant get it to work. Every help is appreciated

2 Answers

Looking at their documentation they mention intentional holds by the system under some conditions, not limited to...

  • When the system receives a new background notification, it discards the older notification and only holds the newest one.

  • If something force quits or kills the app, the system discards the
    held notification.

  • If the user launches the app, the system immediately delivers the
    held notification.

https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app

Related