Skip to main content

Listening to Events


EventsController allows you to subscribe to chat events. You can receive all events or only to events for a specific channels.

Events Controller Delegate

Classes that conform to the EventsControllerDelegate protocol can be used to receive events from the controller.

func eventsController(_ controller: EventsController, didReceiveEvent event: Event)

Client Events

let eventsController: EventsController = client.eventsController()

Channel Events

let eventsController: EventsController = channel.eventsController()

Example: Local Notifications

In this example we create a custom ChatChannelListVC that shows a local notification every time a new message event is received.

class DemoChannelListVC: ChatChannelListVC, EventsControllerDelegate {
lazy var eventsController: EventsController = controller.client.eventsController()

override func viewDidLoad() {
eventsController.delegate = self

func eventsController(_: EventsController, didReceiveEvent event: Event) {
guard let event = event as? MessageNewEvent else { return }

let message = event.message

let content = UNMutableNotificationContent()
content.title = "\( ?? @ \( ??"
content.body = message.text

let request = UNNotificationRequest(
content: content,
trigger: nil

UNUserNotificationCenter.current().add(request) { error in
if let error = error {
log.error("Error when showing local notification: \(error)")

Did you find this page helpful?