Parse push fields

Updated

Parse push notifications fields.

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

Use the FirebaseMessaging.instance.getInitialMessage method to obtain the custom extension fields when the app is opened. The sample code is as follows:

FirebaseMessaging.instance.getInitialMessage().then((message) {
      Map? data = message?.data;
      if (data != null) {
        String f = data['f'] ?? '';
        String t = data['t'] ?? '';
        String m = data['m'] ?? '';
        String g = data['g'] ?? '';
        Object e = data['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.data object is as follows:

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