Parse push fields

Updated

Parse push notifications fields.

After receiving a push notification, you need to parse the data.

Rewrite the FirebaseMessagingService.onMessageReceived method to get a custom extension field in the RemoteMessage object. The sample code is as follows:

messaging().onMessage(async (remoteMessage) => {
  console.log("A new FCM message arrived!", JSON.stringify(remoteMessage));
  // "t":"receiver",
  // "f":"fromUsername",
  // "m":"msg_id",
  // "g":"group_id",
  // "e":{}
});
ParameterDescription
fThe user ID of the push notification sender.
tThe user ID of the push notification recipient.
mThe message ID: A unique identifier of the message.
gThe group ID: This field exists only for group messages.
eThe user-defined extension field.

e is a completely user-defined extension. The data source is em_push_ext.custom of the message extension. The data structure is as follows:

{
    "em_push_ext": {
        "custom": {
            "key1": "value1",
            "key2": "value2"
        }
    }
}

The data structure of the extension in the RemoteMessage object is as follows:

{
  "t": "receiver",
  "f": "fromUsername",
  "m": "msg_id",
  "g": "group_id",
  "e": {}
}