React-native-firebase: iOS FCM messages being received in erroneous form

Created on 8 Jul 2020  ·  16Comments  ·  Source: invertase/react-native-firebase


Issue



I am just looking for information regards the types of the RemoteMessage.
image

All the information for my notification comes inside of data.notification while the typings shows that data and notification properties are part of the RemoteMessage.

Maybe I am doing something wrong so I am here to understand better how is the correct behavior.

iOS Needs Repro Messaging

Most helpful comment

Thanks @mikehardy for clarifications.
But I don't think you & @andersonaddo understood what @Matgsan is saying.

On paper, the documentation describes a RemoteMessage with the following structure:

RemoteMessage {
  notification: Notification
  data: Object // key-value map of strings
  // ...
}

The problem is that it's not what the library gives in runtime.
The given RemoteMessage by the library has the following structure:

RemoteMessage {
  data: {
    notification: Notification
    // other values..
  }
  // ...
}

So there's a bug because the library doesn't follow its documentation.

I must add that the bug is only on iOS.
✅ On Android, the RemoteMessage's structure is like the documentation says.

All 16 comments

image
But for example the Title and Text should come on the data or notification object?

You should only put something in the notification field of you want FCM to handle creating the push notifications on the app automatically. It a simple configuration but not very customizable.

If you want to receive messages that don't automatically create push notifications (like, maybe you want to process and validate the message first or something), then you should send messages that don't have anything in the notification field.
You can read more about those in the react-native-firebase messaging docs and the firebase FCM docs; I don't want to repeat them here 😅

As I can see that you want to make messages that mimic those sent my the console, yes, title and text should be in the notification section 👍

but is not, it is showing under the data.notification object.

Do not confuse cloud messages with notifications.
Notifications are a subset of messages, just one type of payload. (data is the other, and they may mix)
"push" is cloud message pushed to the device so I refuse to use the term "push notification" as it just confuses things. Better to say "cloud message with notification payload".
Without really precise terms everything gets confused

Thanks @mikehardy for clarifications.
But I don't think you & @andersonaddo understood what @Matgsan is saying.

On paper, the documentation describes a RemoteMessage with the following structure:

RemoteMessage {
  notification: Notification
  data: Object // key-value map of strings
  // ...
}

The problem is that it's not what the library gives in runtime.
The given RemoteMessage by the library has the following structure:

RemoteMessage {
  data: {
    notification: Notification
    // other values..
  }
  // ...
}

So there's a bug because the library doesn't follow its documentation.

I must add that the bug is only on iOS.
✅ On Android, the RemoteMessage's structure is like the documentation says.

A sample of a RemoteMessage instance (on iOS):

image

(event & interlocutorId are fields set by the server in data. Don't bother with them)

If I understood correctly from some related issue, there was a difference even in iOS between simulator and device, is that correct? And the correct structure came in on the real device?

If that's correct and the structure is only wrong on simulator then this is a non issue because while I have seen messages come through on simulator, cloud messaging on simulator is specifically not supported by apple, so nothing correct should be expected and no testing should be performed there

Thanks @mikehardy.
You were right, the problem was only on simulator.
On real device the structure is OK.

So that ends the issue.

Okay - sorry for anyone that wasted their time with it but this is the foundation for the rule: on iOS only test cloud messaging on real devices - if that's not clear in any of the docs (it may not be?) a PR there could save others from losing all their hair too. These differences are subtle enough to lure people in

@mikehardy
Unfortunately, I have this problem with real iOS device test. (Android work properly)

I send FCM via http v1 call https://fcm.googleapis.com/v1/projects/<project_id>/messages:send (also tried legacy api)

{
  "message": {
    "notification": {
      "title": "Test",
      "body": "test"
    },
    "token": <token from `messaging().getToken()`>,
    "data": {
      "hello": "world"
    }
  },
  "validateOnly": false
}

and I received JSON within onMessage callback

{
  collapseKey: '...',
  data: {
    hello: 'world',
    notification: { body: 'test', e: '1', title: 'Test' },
  },
  from: '...',
}

I don't have any clue of this problem because I received JSON that I expected a few times. I think too early to close this issue

Indicated below was my test env

  • iOS: 13.5.1
  • model: iPhone SE

strange, I do have an iPhone SE as well but I literally never send notification payloads myself, so I haven't seen this, we'll need a reproduction which sounds difficult unfortunately.

Reopening this then, since the problem isn't technically solved yet.

Just want to point out that while this is a problem, it's a problem with a very trivial workaround (check if notification is present in the root of the FCM message, if it isn't then check for it in data). So don't hold your breath waiting for a solution :)

@yairopro You described right. But as mentioned the issue was just happening on simulator, on the real device it is ok for me at least.

I figured out causes of problem

problem occured when I tried below

1. get token (I don't know why I can get token that not working properly)
2. accept iOS Permission
3. try to send notification via token

So, I reorder of request, work properly on real device

1. accept iOS Permission
2. get token (after granted)
3. try to send notification via token

it was just my mistake..
sorry to make you confused 😵

Was this page helpful?
0 / 5 - 0 ratings