Open Chenjiujiu opened 2 weeks ago
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
Issue
When I send a message with
contentAvailable
set totrue
, 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 tofalse
, 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
```typescript messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('Received message', 'Background'); return Promise.resolve(); }); messaging().onMessage(remoteMessage => { console.log('Received message', 'Foreground'); }) ```
nodejs.
Click To Expand
```typescript 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**: - [x] iOS - [ ] Android - [x] **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
React Native Firebase
andInvertase
on Twitter for updates on the library.