Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setBackgroundMessageHandler is not called in terminated state

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

like image 819
Stevetro Avatar asked Sep 16 '25 13:09

Stevetro


1 Answers

Found it!

Version 7.18.0 - August 13, 2020 Cloud Messaging
Deprecated setBackgroundMessageHandler. Use the new API onBackgroundMessage instead.

https://firebase.google.com/support/release-notes/js#cloud-messaging_2

like image 51
o.o Avatar answered Sep 19 '25 07:09

o.o