reactjs – setBackgroundMessageHandler not triggering when app is killed and another app is in foreground (iOS)


I’m encountering an issue with background notification handling in my React Native app using React Native Firebase on iOS.

Problem Description:

Scenario: When my app is killed and another app is in the foreground, setBackgroundMessageHandler doesn’t execute for FCM notifications.

Expected Behavior: I expect setBackgroundMessageHandler to trigger even when the app is killed, enabling background tasks.

Actual Behavior: The handler only functions when no other app is in the foreground.

Environment:
React Native: 0.71.8
React Native Firebase Messaging: ~15.4.0
iOS Version: 16.3.1
Notifee: 7.7.1
Device Model: iPhone 10 (physical device)

Configuration:
FCM Setup: All good, please believe me;
Background Modes: “Remote notifications” enabled in Xcode;

// payload for fcm server
{
"to": "---this-is-correct-believe-me---",
  "content_available":true,
  "priority":"high",
  "apns": {
    "payload": {
      "aps": {
        "alert": {
          "title": "Test Push",
          "body": "Success! Push notification ! 🎉",
          "sound": "default"
        }
      }
    },
    "headers": {
      "apns-push-type": "background",
      "apns-priority": "10",
      "apns-topic": "---this-is-also-correct-believe-me---"
    }
  },
  "notification": {
    "title": "Test Push",
    "body": "Success! Push notification! 🎉",
    "sound": "default"
  },
  "data": {
    "movieName": "",
  }
}

Troubleshooting Attempts:
Adjusted apns-priority: Tried setting it to 10, but no change.
Reviewed Payload: Verified notification and data fields are present.
Also, I’m using the setBackgroundMessageHandler and onMessage methods as mentioned in the rnfirebase doc.

Seeking guidance on:
Potential causes for this behavior.
Troubleshooting steps to ensure reliable background handling in all scenarios.
Best practices for managing background tasks in React Native Firebase on iOS.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img