Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] setBackgroundMessageHandler() is not working in IOS #8117

Open
2 of 5 tasks
Chenjiujiu opened this issue Nov 6, 2024 · 1 comment
Open
2 of 5 tasks

[🐛] setBackgroundMessageHandler() is not working in IOS #8117

Chenjiujiu opened this issue Nov 6, 2024 · 1 comment
Labels

Comments

@Chenjiujiu
Copy link

Chenjiujiu commented Nov 6, 2024

Issue

When I send a message with contentAvailable set to true,
The setBackgroundMessageHandler on the background device triggers normally,
But the onMessage on the foreground device does not trigger.

When I send a message with contentAvailable set to false,
The setBackgroundMessageHandler on the background device does not trigger,
But the onMessage on the foreground device triggers normally.

However, I want to send a message:
The background device triggers setBackgroundMessageHandler,
And the foreground device triggers onMessage.

So that I can collect the count of message arrivals.


Project Files.

package.json

Click To Expand

  "@react-native-firebase/app": "^19.2.2",
  "@react-native-firebase/messaging": "^19.2.2",
  "react": "18.2.0",
  "react-native": "0.72.6",

index.js.

Click To Expand

messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log('Received message', 'Background');
  return Promise.resolve();
});
messaging().onMessage(remoteMessage => {
  console.log('Received message', 'Foreground');
})

nodejs.

Click To Expand

const message = {
  token: token,
  data: {
    url: 'Product?handle=ccspud23122202222100',
  },
  notification: {
    title: "message test",
    body: now,
    imageUrl: "**********",
  },
  apns: {
    payload: {
      aps: {
        contentAvailable: false,
        sound: "default",
      },
    }
  },
  android: {
    priority: 'high',
  }
};
// send
admin.messaging().send(message)
  .then(( response ) => {
    console.debug(response);
  })
  .catch(( error ) => {
    console.debug(error);
  });


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • 19.2.2
  • Firebase module(s) you're using that has the issue:
    • messaging
  • Are you using TypeScript?
    • 4.8.4


@mikehardy
Copy link
Collaborator

This is intended behavior based on the partial information in your issue
One type of FCM will be delivered in the background and trigger the background handler
One type of FCM will be posted more as a notification and trigger the foreground handler after user interaction

Suggestion: Make a more universal handler that can be registered for all the callbacks, count delivery in that single place.

Either way: without knowing the exact contents of the FCM you send to the device and the handler code (as a minimal reproducible example) I would not expect authoritative answers, as there is no authoritative information to work with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants