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. try { // Unsubscribe from the topic. KiiUser user = KiiUser.getCurrentUser(); KiiPushSubscription sub = user.pushSubscription(); sub.unsubscribe(topic); } catch (IOException ioe) { // Handle the error. } catch (AppException e) { // Handle the error. }
-
// Assume that the current user is subscribed to the target topic and // the topic has been instantiated. // Unsubscribe from the topic. KiiUser user = KiiUser.getCurrentUser(); KiiPushSubscription sub = user.pushSubscription(); sub.unsubscribe(topic, new KiiPushCallBack() { @Override public void onUnSubscribeCompleted(int taskId, KiiSubscribable target, Exception exception) { if (exception != null) { // Handle the error. return; } } });
- Creates a
KiiPushSubscription
instance by calling thepushSubscription
method. - Calls the
unsubscribe
method passing the target topic.