react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

iOS Data Only FCM messages not reaching device

Open sudhay23 opened this issue 1 year ago • 2 comments

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

sudhay23 avatar Apr 27 '24 15:04 sudhay23

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

mikehardy avatar May 02 '24 13:05 mikehardy

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 ?

thanatas avatar May 07 '24 10:05 thanatas

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

mikehardy avatar May 20 '24 16:05 mikehardy