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.

Swift:

  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    do{
      // Unsubscribe from the topic.
      try KiiUser.current()!.pushSubscription().unsubscribeSynchronous(topic)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    // Unsubscribe from the topic.
    KiiUser.current()!.pushSubscription().unsubscribe(topic) { (subscription : KiiPushSubscription, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    NSError *error = nil;
    
    // Unsubscribe from the topic.
    KiiPushSubscription *unsubscribe = [[KiiUser currentUser].pushSubscription unsubscribeSynchronous:topic
                                                                                                error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Assume that the current user is subscribed to the target topic and
    // the topic has been instantiated.
    
    // Unsubscribe from the topic.
    [[KiiUser currentUser].pushSubscription unsubscribe:topic
                                                  block:^(KiiPushSubscription *subscription, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

Calls the unsubscribeSynchronous:error: method while passing the target topic.