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. You can get information such as the updated bucket and object, and the type of change (addition, deletion and so on) with the Push To App mechanism.

{
  "modifiedAt":1463364001875,
  "origin":"EVENT",
  "objectScopeType":
  "APP_AND_USER",
  "bucketID":"myBucket",
  "type":"DATA_OBJECT_CREATED",
  "when":1463364001908,
  "bucketType":"rw",
  "sender":"727f20b00022-8d18-5e11-991f-06db2509",
  "sourceURI":"kiicloud://users/727f20b00022-8d18-5e11-991f-06db2509/buckets/myBucket/objects/e697ea30-1b09-11e6-ab1e-22000b02f727",
  "appID":"12345678",
  "objectScopeAppID":"12345678",
  "objectScopeUserID":"727f20b00022-8d18-5e11-991f-06db2509",
  "objectID":"e697ea30-1b09-11e6-ab1e-22000b02f727"
}

You cannot customize the content of the push message sent with the Push To App feature. See Customizing a push message for workarounds.

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 App notification feature, if the notification reception process updates the subscribed bucket, 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.