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
SceneDelegateis 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 inSceneDelegateto handle the connection and configuration of the scene. Check theconnectionOptionsparameter in thescene ( _ : willConnectTo:options:)method ofSceneDelegateto 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
SceneDelegateis not used in the app, the system will pass the user-defined information in the push to the app throughlaunchOptionsin theapplication:didFinishLaunchingWithOptions:method. Check thelaunchOptionsparameter 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"
}| 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. |
