Parse push fields

Updated

Parse push notifications fields.

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:

    - (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.

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

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

{
    "aps":{
        "alert":{
            "body" : "You have a new message"
        },
        "badge":1,
        "sound":"default"
    },
    "f":"6001",
    "t":"6006",
    "g":"1421300621769",
    "m":"373360335316321408"
}
ParameterDescription
bodyThe push content.
badgeThe badge.
soundThe ringtone.
fThe message sender ID.
tThe message recipient ID.
gThe group ID. This field exists only for group messages.
mThe message ID.