invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.5k stars 2.18k forks source link

iOS Data Only FCM messages not reaching device #7770

Closed sudhay23 closed 3 weeks ago

sudhay23 commented 1 month ago

Hello, I am trying to send a data-only message to an iOS simulator react native app but the callback function in messaging().setBackgroundMessageHandler(onMessageReceived); is not being triggered where I am trying to show a Notifee notification.

const onMessageReceived = async (_message) => {
  // console.log("first", _message);
  // Display a notification

  await notifee.displayNotification({
    title: "From Backend - DATA ONLY",
    body: _message.data,
  });
};

On backend (Node.js)

const message: Message = {
    token: RECEIVER_TOKEN,
    // For FCM Notification Display
    // notification: {
    //   title: "Hello",
    //   body: "World",
    // },
    // If client app wishes to display local notification with additional content
    data: { value: "TESTER BACKEND" },
    // Android Specific Settings
    android: {
      priority: "high",
    },
    apns: {
      payload: { aps: { contentAvailable: true } },
      headers: {
        "apns-push-type": "background",
        "apns-priority": "5",
        "apns-topic": "", // your app bundle identifier
      },
    },
  };

Please assist. Thanks

mikehardy commented 1 month ago

data-only message to an iOS

data-only messages will never be reliable on iOS, if you ever receive them it is a bonus. If you want to have FCM delivered on iOS you need to send a notification block in the FCM

thanatas commented 1 month ago

I am also struggling to get message in IOS emulator. I want to know that on M3 Apple MacBook + Emulator, Is it possible? OR I am trying for nothing, Is it ?

mikehardy commented 3 weeks ago

If you have an up to date macOS and Xcode and iOS version on Apple Silicon, and you have granted your app notification permissions, and then restarted your app, and you then register for remote notifications, it should be possible.

BUT NOT DATA-ONLY MESSAGES ON iOS, those may work they may not but they are unreliable and not useful for testing (since they are unreliable is it a real negative test result for no delivery where your code and config is wrong or a false negative test result for no delivery where system just didn't deliver?). use notification blocks

I do not believe anything here will result in changes to the code in this library, and that's what we use open issues to track so I'm going to close this as a user-specific item - you may find stackoverflow good for firebase support as well, the firebase team hangs out there and helps respond to questions