Skip to content

Removing Listeners

Listener objects can be removed when the application is no longer interested in receiving real-time updates. A listener (or all of them) should be removed from the same event handler object which they were added to. The following listener removal APIs are available:

Removing all listeners

The method removes all registered listeners for the update event:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
[eventHandler removeUpdateListeners];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
[eventHandler removeUpdateListeners];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
eventHandler?.removeUpdateListeners()

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeUpdateListeners()

The method below removes all listeners which process events for a specific where clause. The value of the whereClause argument must be the same as one in the addUpdateListener method:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
[eventHandler removeUpdateListenersWithWhereClause:@"orderAmount > 1000"];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
[eventHandler removeUpdateListenersWithWhereClause:@"orderAmount > 1000"];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
eventHandler?.removeUpdateListeners(whereClause: "orderAmount > 1000")

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeUpdateListeners(whereClause: "orderAmount > 1000")

Removing a specific listener

This method removes a listener identified by a subscription that contains this listener:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
RTSubscription *subscription = [eventHandler addUpdateListenerWithResponseHandler:^(Order *updatedObject) {
    NSLog(@"Object has been updated: %@", updatedObject);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];

[subscription stop];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
RTSubscription *subscription = [eventHandler addUpdateListenerWithResponseHandler:^(NSDictionary *updatedObject) {
    NSLog(@"Object has been updated: %@", updatedObject);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}]; 

[subscription stop];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
let subscription = eventHandler?.addUpdateListener(responseHandler: { updatedObject in
    print("Object has been updated: \(updatedObject)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

subscription?.stop()

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
let subscription = eventHandler?.addUpdateListener(responseHandler: { updatedObject in
    print("Object has been updated: \(updatedObject)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

subscription?.stop()