Unsubscribing from a Topic

When a user no longer wants to receive push messages, the user can stop receiving the messages by simply unsubscribing the topic.

See the following sample code to see how you can unsubscribe from a topic.

  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    // Unsubscribe from the topic.
    var user = KiiUser.getCurrentUser();
    user.pushSubscription().unsubscribe(topic, {
      success: function(thePushSubscription, theTopic) {
        // Do something.
      },
      failure: function(thePushSubscription, errorString) {
        // Handle the error.
      }
    });
  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    // Unsubscribe from the topic.
    var user = KiiUser.getCurrentUser();
    user.pushSubscription().unsubscribe(topic).then(
      function(params) {
        var thePushSubscription = params[0];
        var theTopic = params[1];
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var thePushSubscription = error.target;
        var errorString = error.message;
      }
    );
  • Creates a KiiPushSubscription instance by calling the pushSubscription method.
  • Calls the unsubscribe method passing the target topic.