Receiving a Direct Push Notification

The method to receive push notifications varies depending on the method to provide push notifications. This topic describes how to receive push notifications with MQTT over WebSocket. If you are to receive push notifications with Cordova apps, refer phonegap-plugin-push for the detailed information.

Push notifications can be received by processing the MQTT PUBLISH command via an external library. The payload of the PUBLISH command contains a JSON string which includes a custom field specified on the developer portal.

See the KiiPushSubscription section of the Kii Cloud SDK for Android to learn about parameters included in the payload.

MQTT topics

Ensure to check the MQTT topic name on receiving the PUBLISH command from the server because the PUBLISH command is used for various purposes. Also, ignore PUBLISH commands with unknown MQTT topic names for future enhancement.

The MQTT topic name to be received in the push notification is the one subscribed by the SUBSCRIBE command in initialization. Refer to the sample code in the tutorial.

Push message example

The following example shows a formatted payload in a received push message. This example assumes that Hello was specified for mymessage on the developer portal.

{
  "sourceURI":"kiicloud://users/727f20b00022-8d18-5e11-991f-06db2509",
  "mymessage":"Hello",
  "senderURI":"kiicloud://admins/APP_ADMIN"
}