Skip to main content

Event delegation overview

Nexconn Chat SDK delivers real-time events through handler protocols. Each protocol covers a specific domain — group channels, open channels, messages, users, and so on. You register handlers via NCEngine using a unique identifier string, which lets you add multiple independent listeners for the same event type and remove them individually.

How it works

All handler protocols follow the same three-step pattern:

  1. Register — call the addXxxHandler(identifier:handler:) class method on NCEngine before you expect events.
  2. Implement — adopt the protocol and implement only the callbacks you care about. All protocol methods are @optional.
  3. Remove — call removeXxxHandler(forIdentifier:) when the handler is no longer needed (for example, in viewDidDisappear or deinit).
swift
import NexconnChatSDK
// Register
NCEngine.addGroupChannelHandler(identifier: "MyHandler", handler: self)
// Remove
NCEngine.removeGroupChannelHandler(forIdentifier: "MyHandler")

All callbacks deliver an event object. The event object carries all the data relevant to that event. Read the details through its properties rather than through separate parameters.

swift
import NexconnChatSDK
func onGroupOperation(_ event: GroupOperationEvent) {
print("Group: \(event.groupId), operation: \(event.operation.rawValue)")
}

Available handler protocols

ProtocolRegister/Remove method prefixWhat it covers
NCGroupChannelHandleraddGroupChannelHandlerGroup operations, profile changes, member changes, join requests
NCOpenChannelHandleraddOpenChannelHandlerOpen channel enter/exit lifecycle, metadata, members, mute, ban
NCChannelHandleraddChannelHandlerChannel list sync, pinned/DND/translate settings, typing status, community sub-channel events
NCUserHandleraddUserHandlerSubscription events, friend add/delete/apply/clear
NCUserSettingsHandleraddUserSettingsHandlerUser-level settings sync completed
NCMessageHandleraddMessageHandlerMessage receive, delete, modify, read receipts, stream messages, metadata
NCTagEventHandleraddTagHandlerTag and channel-tag changes (multi-device sync)
NCTranslateHandleraddTranslateHandlerTranslation language changes and auto-translate state
NCDatabaseStatusHandleraddDatabaseStatusHandlerDatabase schema upgrade lifecycle
NCConnectionStatusHandleraddConnectionStatusHandlerSDK connection status changes

See the individual pages for full callback details and code examples.