Checking the Subscription Status of a Bucket

Here is the sample code for checking the subscription.

  • // Instantiate the target bucket.
    var user = KiiUser.getCurrentUser();
    var bucket = user.bucketWithName("_target_bucket_");
    
    // Check if the current user is subscribed to the bucket.
    user.pushSubscription().isSubscribed(bucket).then(
      function(params) {
        var thePushSubscription = params[0];
        var theBucket = params[1];
        var isSubscribed = params[2];
        if(isSubscribed) {
          // The current user is subscribed to the bucket.
        } else {
          // The current user is not subscribed to the bucket.
        }
      }
    ).catch(
      function(error) {
        // Handle the error.
        var thePushSubscription = error.target;
        var errorString = error.message;
      }
    );
  • // Instantiate the target bucket.
    var user = KiiUser.getCurrentUser();
    var bucket = user.bucketWithName("_target_bucket_");
    
    // Check if the current user is subscribed to the bucket.
    user.pushSubscription().isSubscribed(bucket, {
      success: function(thePushSubscription, theBucket, isSubscribed) {
        if(isSubscribed) {
          // The current user is subscribed to the bucket.
        } else {
          // The current user is not subscribed to the bucket.
        }
      },
      failure: function(errorString) {
        // Handle the error.
      }
    });