Skip to main content

Monitor connection status

The Chat UI SDK provides the NCChatUIConnectionStatusDelegate protocol to monitor IM connection status changes. By listening to these changes, your app can handle different business logic or display status notifications.

Add or remove delegate listeners

You should set up connection status listeners after initializing the Chat UI SDK with your AppKey but before connecting to IM. Multiple listeners are supported.

To prevent memory leaks, remove the delegate when you no longer need to monitor connection status.

tip

Assign the delegate to a singleton object like AppDelegate to ensure it remains active throughout the app lifecycle.

Objective C
/// Add delegate
[[NCChatUI shared] addConnectionStatusDelegate:self];

/// Remove delegate
[[NCChatUI shared] removeConnectionStatusDelegate:self];

Connection status change protocol

The NCChatUIConnectionStatusDelegate protocol is defined as:

Objective C
@protocol NCChatUIConnectionStatusDelegate <NSObject>

- (void)onNCChatUIConnectionStatusChanged:(NCConnectionStatus)status;

@end

When the connection status changes, the SDK calls - (void)onNCChatUIConnectionStatusChanged:(NCConnectionStatus)status; to notify listeners of the current status. The NCConnectionStatus enum defines possible connection states. The following table explains key status codes your app should handle.

Status codeValueDescription
NCConnectionStatusKickedOfflineByOtherClient6Current user logged in from another device, kicking this device offline
NCConnectionStatusTimeout14Auto-connection timed out. The SDK won't retry - your app should handle the timeout and manually reconnect
NCConnectionStatusTokenIncorrect15Invalid access token. Typically occurs when the client SDK and app server use different App Keys, or when the token expired
NCConnectionStatusDisconnException16Connection to server lost due to user ban
NCConnectionStatusProxyUnavailable17Proxy service unavailable
NCConnectionStatusUserAbandon19User account deactivated