Receiving a 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.


Preventing an infinite loop of push notifications

When designing and implementing the push notification feature, ensure that your mobile app does not cause an infinite loop of push notifications. If the notification reception process triggers another push notification, there is no way to stop the infinite loop.

Specifically for the Push to User notification feature, if the notification reception process sends a push message to the subscribed topic, it will cause an infinite loop.

If your release module caused an infinite loop, it would be very difficult to solve the issue. To fix it fundamentally, your mobile app on every end-user's device must be updated to a fixed version. Until the update is complete, you would need to delete the key or the certificates in the developer portal or unsubscribe each user from the bucket by using the REST API.