User-level events
Use NCUserHandler to receive user-level event callbacks — including subscription event changes, friend relationship changes, and multi-device sync notifications.
Register the handler via NCEngine with a unique identifier string:
- Swift
- Objective-C
swift
import NexconnChatSDK
// Register
NCEngine.addUserHandler(identifier: "MY_USER_HANDLER", handler: self)
// Remove
NCEngine.removeUserHandler(forIdentifier: "MY_USER_HANDLER")
Objective C
// Register
[NCEngine addUserHandlerWithIdentifier:@"MY_USER_HANDLER" handler:self];
// Remove
[NCEngine removeUserHandlerForIdentifier:@"MY_USER_HANDLER"];
Implement NCUserHandler
All methods are optional. Implement the callbacks you need.
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyViewController: NSObject, UserHandler {
// Subscription event changed (e.g., online status update)
func onSubscriptionChanged(_ event: SubscriptionChangedEvent) {
for info in event.events {
print("User event changed: \(info.userId)")
}
}
// Subscription data sync completed
func onSubscriptionSyncCompleted(_ event: SubscriptionSyncCompletedEvent) {
print("Subscription synced for type: \(event.type.rawValue)")
}
// Subscription info changed on another device
func onSubscriptionChangedOnOtherDevices(_ event: SubscriptionChangedOnOtherDevicesEvent) {
print("Subscription changed on another device, count: \(event.events.count)")
}
// Friend added
func onFriendAdd(_ event: FriendAddEvent) {
print("Friend added: \(event.userId)")
}
// Friend deleted
func onFriendDelete(_ event: FriendDeleteEvent) {
print("Friends deleted: \(event.userIds)")
}
// All friends cleared (server-triggered only)
func onFriendCleared(_ event: FriendClearedEvent) {
print("All friends cleared at: \(event.operationTime)")
}
// Friend application status changed
func onFriendApplicationStatusChanged(_ event: FriendApplicationStatusChangedEvent) {
print("Friend application from \(event.userId) status: \(event.applicationStatus.rawValue)")
}
// Friend info changed on another device (multi-device sync)
func onFriendInfoChangedSync(_ event: FriendInfoChangedSyncEvent) {
print("Friend info synced for: \(event.userId)")
}
}
Objective C
@interface MyViewController () <NCUserHandler>
@end
@implementation MyViewController
// Subscription event changed (e.g., online status update)
- (void)onSubscriptionChanged:(NCSubscriptionChangedEvent *)event {
for (NCSubscriptionStatusInfo *info in event.events) {
NSLog(@"User event changed: %@", info.userId);
}
}
// Subscription data sync completed
- (void)onSubscriptionSyncCompleted:(NCSubscriptionSyncCompletedEvent *)event {
NSLog(@"Subscription synced for type: %ld", (long)event.type);
}
// Subscription info changed on another device
- (void)onSubscriptionChangedOnOtherDevices:(NCSubscriptionChangedOnOtherDevicesEvent *)event {
NSLog(@"Subscription changed on another device, count: %lu", (unsigned long)event.events.count);
}
// Friend added
- (void)onFriendAdd:(NCFriendAddEvent *)event {
NSLog(@"Friend added: %@", event.userId);
}
// Friend deleted
- (void)onFriendDelete:(NCFriendDeleteEvent *)event {
NSLog(@"Friends deleted: %@", event.userIds);
}
// All friends cleared (server-triggered only)
- (void)onFriendCleared:(NCFriendClearedEvent *)event {
NSLog(@"All friends cleared at: %lld", (long long)event.operationTime);
}
// Friend application status changed
- (void)onFriendApplicationStatusChanged:(NCFriendApplicationStatusChangedEvent *)event {
NSLog(@"Friend application from %@ status: %ld",
event.userId, (long)event.applicationStatus);
}
// Friend info changed on another device (multi-device sync)
- (void)onFriendInfoChangedSync:(NCFriendInfoChangedSyncEvent *)event {
NSLog(@"Friend info synced for: %@", event.userId);
}
@end
Callback reference
| Callback | Event type | Trigger |
|---|---|---|
onSubscriptionChanged: | NCSubscriptionChangedEvent | One or more subscription events changed (e.g., online status). Use event.events to iterate. |
onSubscriptionSyncCompleted: | NCSubscriptionSyncCompletedEvent | Subscription data sync completed. Use event.type to identify the subscription type. |
onSubscriptionChangedOnOtherDevices: | NCSubscriptionChangedOnOtherDevicesEvent | Subscription info changed on another device of the same user. Use event.events to iterate. |
onFriendAdd: | NCFriendAddEvent | A friend was added. Use fields like event.userId, event.name, and event.operationTime. |
onFriendDelete: | NCFriendDeleteEvent | One or more friends were removed. Use event.userIds for the affected list. |
onFriendCleared: | NCFriendClearedEvent | All friends were cleared by a server-side operation. Use event.operationTime for the timestamp. |
onFriendApplicationStatusChanged: | NCFriendApplicationStatusChangedEvent | A friend request status changed. Use fields like event.userId and event.applicationStatus. |
onFriendInfoChangedSync: | NCFriendInfoChangedSyncEvent | Friend info changed on another device (multi-device sync). Use fields like event.userId and event.remark. |
NCUserSettingsHandler
To receive user-level settings sync events, register an NCUserSettingsHandler separately:
- Swift
- Objective-C
swift
import NexconnChatSDK
// Register
NCEngine.addUserSettingsHandler(identifier: "MY_SETTINGS_HANDLER", handler: self)
// Remove
NCEngine.removeUserSettingsHandler(forIdentifier: "MY_SETTINGS_HANDLER")
Objective C
// Register
[NCEngine addUserSettingsHandlerWithIdentifier:@"MY_SETTINGS_HANDLER" handler:self];
// Remove
[NCEngine removeUserSettingsHandlerForIdentifier:@"MY_SETTINGS_HANDLER"];
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyViewController: NSObject, UserSettingsHandler {
func onUserSettingsSyncCompleted(_ event: UserSettingsSyncCompletedEvent) {
if event.error == nil {
print("User settings synced successfully.")
} else {
print("User settings sync failed: \(event.error!.localizedDescription)")
}
}
}
Objective C
@interface MyViewController () <NCUserSettingsHandler>
@end
@implementation MyViewController
- (void)onUserSettingsSyncCompleted:(NCUserSettingsSyncCompletedEvent *)event {
if (event.error == nil) {
NSLog(@"User settings synced successfully.");
} else {
NSLog(@"User settings sync failed: %@", event.error);
}
}
@end