Skip to main content

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
import NexconnChatSDK
// Register
NCEngine.addUserHandler(identifier: "MY_USER_HANDLER", handler: self)
// Remove
NCEngine.removeUserHandler(forIdentifier: "MY_USER_HANDLER")

Implement NCUserHandler

All methods are optional. Implement the callbacks you need.

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)")
}
}

Callback reference

CallbackEvent typeTrigger
onSubscriptionChanged:NCSubscriptionChangedEventOne or more subscription events changed (e.g., online status). Use event.events to iterate.
onSubscriptionSyncCompleted:NCSubscriptionSyncCompletedEventSubscription data sync completed. Use event.type to identify the subscription type.
onSubscriptionChangedOnOtherDevices:NCSubscriptionChangedOnOtherDevicesEventSubscription info changed on another device of the same user. Use event.events to iterate.
onFriendAdd:NCFriendAddEventA friend was added. Use fields like event.userId, event.name, and event.operationTime.
onFriendDelete:NCFriendDeleteEventOne or more friends were removed. Use event.userIds for the affected list.
onFriendCleared:NCFriendClearedEventAll friends were cleared by a server-side operation. Use event.operationTime for the timestamp.
onFriendApplicationStatusChanged:NCFriendApplicationStatusChangedEventA friend request status changed. Use fields like event.userId and event.applicationStatus.
onFriendInfoChangedSync:NCFriendInfoChangedSyncEventFriend 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
import NexconnChatSDK
// Register
NCEngine.addUserSettingsHandler(identifier: "MY_SETTINGS_HANDLER", handler: self)
// Remove
NCEngine.removeUserSettingsHandler(forIdentifier: "MY_SETTINGS_HANDLER")
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)")
}
}
}