# Parse push fields (/en/realtime-media/im/build/notifications-and-event-handling/offline-push/parse-push-fields)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

<_PlatformTabsGroup groupMode="structured" canonicalPlatform="web" platforms="[&#x22;android&#x22;,&#x22;ios&#x22;,&#x22;flutter&#x22;,&#x22;react-native&#x22;,&#x22;web&#x22;,&#x22;windows&#x22;,&#x22;unity&#x22;]" showTabs="true">
  <_PlatformPanel platform="android">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" />

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

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

    ```java
    public class FCMMSGService extends FirebaseMessagingService {
        @Override
        public void onMessageReceived(RemoteMessage remoteMessage) {
            super.onMessageReceived(remoteMessage);
            if (remoteMessage.getData().size() > 0) {
                String f = remoteMessage.getData().get("f");
                String t = remoteMessage.getData().get("t");
                String m = remoteMessage.getData().get("m");
                String g = remoteMessage.getData().get("g");
                Object e = remoteMessage.getData().get("e");
            }
        }

        @Override
        public  void  handleIntent ( @NonNull  Intent  intent ) {
            super.handleIntent(intent);
            Bundle bundle = intent . getExtras();
            if (bundle != null) {
                Map map = new HashMap<>();
                for (String key : bundle.keySet()) {
                    if (!TextUtils.isEmpty(key)) {
                    Object content = bundle.get(key);
                    map.put(key, content);
                    }
                }
                Log.i(TAG, "handleIntent: " + map);
            }
       }
    }
    ```

    | Parameter | Description                                              |
    | --------- | -------------------------------------------------------- |
    | `f`       | The user ID of the push notification sender.             |
    | `t`       | The user ID of the push notification recipient.          |
    | `m`       | The message ID: A unique identifier of the message.      |
    | `g`       | The group ID: This field exists only for group messages. |
    | `e`       | The 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:

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

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

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

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="ios">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" />

    When the device receives a push notification and a user clicks it, the system will pass the custom push content (JSON) to the app. This allows you to customize the behavior triggered by clicking the push notification according to the push content, such as page routing. When a push notification is received and clicked, the app obtains the push content as follows:

    * If `SceneDelegate` is used in the app, the app startup process is managed by the scene system. When you click the offline push message to open the app, the app will start the scene and then call the corresponding method in `SceneDelegate` to handle the connection and configuration of the scene. Check the `connectionOptions` parameter in the `scene ( _ : willConnectTo:options:)` method of `SceneDelegate` to get the push content. The sample code is as follows:

      ```objc
      - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
          // Get the startup options
          NSDictionary *launchOptions = connectionOptions.notificationResponse.notification.request.content.userInfo;
          // Perform corresponding processing
          // ...
      }
      ```

    * If `SceneDelegate` is not used in the app, the system will pass the user-defined information in the push to the app through `launchOptions` in the `application:didFinishLaunchingWithOptions:` method. Check the `launchOptions` parameter to get the push content.

      ```objc
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
            NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
        }
      ```

    The data structure of the user-defined `userInfo` is as follows:

    ```json
    {
        "aps":{
            "alert":{
                "body" : "You have a new message"
            },
            "badge":1,
            "sound":"default"
        },
        "f":"6001",
        "t":"6006",
        "g":"1421300621769",
        "m":"373360335316321408"
    }
    ```

    | Parameter | Description                                              |
    | :-------- | :------------------------------------------------------- |
    | `body`    | The push content.                                        |
    | `badge`   | The badge.                                               |
    | `sound`   | The ringtone.                                            |
    | `f`       | The message sender ID.                                   |
    | `t`       | The message recipient ID.                                |
    | `g`       | The group ID. This field exists only for group messages. |
    | `m`       | The message ID.                                          |

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="flutter">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" />

    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:

    ```dart
    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'] ?? '';
          }
    });
    ```

    | Parameter | Description                                              |
    | --------- | -------------------------------------------------------- |
    | `f`       | The user ID of the push notification sender.             |
    | `t`       | The user ID of the push notification recipient.          |
    | `m`       | The message ID: A unique identifier of the message.      |
    | `g`       | The group ID: This field exists only for group messages. |
    | `e`       | The 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:

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

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

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

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="react-native">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="react-native" />

    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:

    ```typescript
    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":{}
    });
    ```

    | Parameter | Description                                              |
    | --------- | -------------------------------------------------------- |
    | `f`       | The user ID of the push notification sender.             |
    | `t`       | The user ID of the push notification recipient.          |
    | `m`       | The message ID: A unique identifier of the message.      |
    | `g`       | The group ID: This field exists only for group messages. |
    | `e`       | The 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:

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

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

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

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="web">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" />

    **This feature guide is not available yet.**

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="windows">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="windows" />

    **This feature is not supported for this platform.**

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="unity">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" />

    **This feature is not supported for this platform.**

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>
</_PlatformTabsGroup>
