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:
- Register — call the
addXxxHandler(identifier:handler:)class method onNCEnginebefore you expect events. - Implement — adopt the protocol and implement only the callbacks you care about. All protocol methods are
@optional. - Remove — call
removeXxxHandler(forIdentifier:)when the handler is no longer needed (for example, inviewDidDisappearordeinit).
- Swift
- Objective-C
swift
import NexconnChatSDK
// Register
NCEngine.addGroupChannelHandler(identifier: "MyHandler", handler: self)
// Remove
NCEngine.removeGroupChannelHandler(forIdentifier: "MyHandler")
Objective C
// Register
[NCEngine addGroupChannelHandlerWithIdentifier:@"MyHandler" handler:self];
// Remove
[NCEngine removeGroupChannelHandlerForIdentifier:@"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
- Objective-C
swift
import NexconnChatSDK
func onGroupOperation(_ event: GroupOperationEvent) {
print("Group: \(event.groupId), operation: \(event.operation.rawValue)")
}
Objective C
- (void)onGroupOperation:(NCGroupOperationEvent *)event {
NSLog(@"Group: %@, operation: %ld", event.groupId, (long)event.operation);
}
Available handler protocols
| Protocol | Register/Remove method prefix | What it covers |
|---|---|---|
NCGroupChannelHandler | addGroupChannelHandler | Group operations, profile changes, member changes, join requests |
NCOpenChannelHandler | addOpenChannelHandler | Open channel enter/exit lifecycle, metadata, members, mute, ban |
NCChannelHandler | addChannelHandler | Channel list sync, pinned/DND/translate settings, typing status, community sub-channel events |
NCUserHandler | addUserHandler | Subscription events, friend add/delete/apply/clear |
NCUserSettingsHandler | addUserSettingsHandler | User-level settings sync completed |
NCMessageHandler | addMessageHandler | Message receive, delete, modify, read receipts, stream messages, metadata |
NCTagEventHandler | addTagHandler | Tag and channel-tag changes (multi-device sync) |
NCTranslateHandler | addTranslateHandler | Translation language changes and auto-translate state |
NCDatabaseStatusHandler | addDatabaseStatusHandler | Database schema upgrade lifecycle |
NCConnectionStatusHandler | addConnectionStatusHandler | SDK connection status changes |
See the individual pages for full callback details and code examples.