Push To App Notification

The Push to App notification feature allows receiving push notifications for updates in a subscribed bucket. See Push to App Notification for the overview of how it works.

Subscribing to a bucket

See the below sample code for subscribing to a bucket to start monitoring. After monitoring is started, a push notification will be sent to the mobile app whenever a change occurs in any KiiObjects in this bucket.

int ret;

/* Set bucket parameters. */
kii_bucket_t bucket;
memset(&bucket, 0x00, sizeof(kii_bucket_t));
bucket.scope = KII_SCOPE_THING;
bucket.bucket_name = "myBucket";
bucket.scope_id = "VENDOR_THING_ID:rBnvSPOXBDF9r29GJeGS";

/* Subscribe to the bucket. */
ret = kii_push_subscribe_bucket(&kii, &bucket);
if (ret != 0) {
  /* Handle the error. */
  return;
}

Specify a bucket to subscribe to with the kii_bucket_t structure. See Creating a KiiObject to learn how to specify it. You can subscribe to buckets only in the thing scope and application scope.

Use the Push to User notification feature if you want to be notified of changes in the owner's data. Receive a push message via a topic when a bucket is updated.

Unsubscribing from a bucket

See the below sample code for unsubscribing from a bucket. After unsubscribing from a bucket, changes in the KiiObjects in the bucket will not trigger push notifications for the bucket.

int ret;

/* Set bucket parameters. */
kii_bucket_t bucket;
memset(&bucket, 0x00, sizeof(kii_bucket_t));
bucket.scope = KII_SCOPE_THING;
bucket.bucket_name = "myBucket";
bucket.scope_id = "VENDOR_THING_ID:rBnvSPOXBDF9r29GJeGS";

/* Unsubscribe from the bucket. */
ret = kii_push_unsubscribe_bucket(&kii, &bucket);
if (ret != 0) {
  /* Handle the error. */
  return;
}

Receiving a Push To App notification

Set the reception handler to receive a push notification. See Implementing the Reception Handler to learn how to implement it.

Example of a push message

See below for the sample data received as a Push to App notification. You can get information such as an updated bucket, KiiObject, and the type of update (addition, deletion, and so on) as an argument of the handler.

See the Javadoc for the Kii Cloud SDK for Android for more information about the data in a Push to App message.

{
  "appID": "11111111",
  "bucketID": "myBucket",
  "bucketType": "rw",
  "modifiedAt": 1470109920976,
  "objectID": "77b5dd00-5864-11e6-935b-22000aad0899",
  "objectScopeAppID": "11111111",
  "objectScopeThingID": "th.727f20b00022-e1ba-6e11-18c2-0af88aeb",
  "objectScopeType": "APP_AND_THING",
  "origin": "EVENT",
  "sourceURI": "kiicloud://things/th.727f20b00022-e1ba-6e11-18c2-0af88aeb/buckets/myBucket/objects/77b5dd00-5864-11e6-935b-22000aad0899",
  "type": "DATA_OBJECT_CREATED",
  "when": 1470109921000
}

You cannot customize the data in a Push to App message. See Customizing a push message for workarounds.