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 delete event:

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

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

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

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 addDeleteListener method:

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

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

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeDeleteListeners(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 addDeleteListenerWithResponseHandler:^(Order *deletedObject) {
    NSLog(@"Order has been deleted: %@", deletedObject);
} 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 addDeleteListenerWithResponseHandler:^(NSDictionary *deletedObject) {
    NSLog(@"Order has been deleted: %@", deletedObject);
} 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?.addDeleteListener(responseHandler: { deletedObject in
    print("Order has been deleted: \(deletedObject)")
}, 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?.addDeleteListener(responseHandler: { deletedObject in
    print("Order has been deleted: \(deletedObject)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

subscription?.stop()