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

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

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

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

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

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

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

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeCreateListeners(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 addCreateListenerWithResponseHandler:^(Order *createdObject) {
    NSLog(@"Object has been created: %@", createdObject);
} 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 addCreateListenerWithResponseHandler:^(NSDictionary *createdObject) {
    NSLog(@"Object has been created: %@", createdObject);
} 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?.addCreateListener(responseHandler: { createdObject in
    print("Object has been created: \(createdObject)")
}, 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?.addCreateListener(responseHandler: { createdObject in
    print("Object has been created: \(createdObject)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})
subscription?.stop()