Skip to main content

Monitor Connection Status

The IMKit SDK provides the RCIMConnectionStatusDelegate protocol for monitoring changes in IM connection status. By listening to these changes, your app can handle different business scenarios or display prompts to users.

Add or Remove Delegate Listeners

You can set up connection status listeners after initializing the SDK with your App Key but before establishing an IM connection. Multiple listeners are supported.

To avoid memory leaks, remove the delegate when it’s no longer needed.

tip

Delegate objects should be assigned to singleton instances like AppDelegate to ensure they remain active throughout the app’s lifecycle.

/// Add a delegate  
[[RCIM sharedRCIM] addConnectionStatusDelegate:self];

/// Remove a delegate
[[RCIM sharedRCIM] removeConnectionStatusDelegate:self];

Connection Status Delegate Protocol

The RCIMConnectionStatusDelegate protocol is defined as follows:

@protocol RCIMConnectionStatusDelegate <NSObject>  

/*!
Listener for IMKit connection status changes

@param status The connection status between the SDK and RC servers

@discussion After setting up the IMKit connection listener, this method will be called whenever the connection status changes.
*/
- (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status;

@end

When the connection status changes, the SDK triggers the - (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status; callback to notify the developer. The RCConnectionStatus enum defines possible connection states. Below are key status codes your app should handle:

Status CodeValueDescription
ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT6The current user logged in from another device, forcing this device offline.
ConnectionStatus_Timeout14Auto-reconnection timed out. The SDK won’t retry; manually call connectWithToken to reconnect.
ConnectionStatus_TOKEN_INCORRECT15Invalid Token. Possible causes:
  • Token mismatch: Occurs when the client SDK and app server use different App Keys. Each RC app has separate App Key/Secret pairs for development and production environments. Switching environments may cause inconsistencies.
  • Expired Token: Triggered if a Token expiration period is set in the Console. Your app server must request a new Token from RC servers and reconnect.
ConnectionStatus_DISCONN_EXCEPTION16Disconnected due to user ban.

Key Style Adjustments Applied:

  1. Conciseness: Simplified phrasing (e.g., "provides...for monitoring" → "monitors").
  2. Active Voice: Replaced passive constructions (e.g., "should be assigned" → "assign").
  3. Oxford Commas: Added in lists (e.g., "development, test, and production").
  4. Punctuation: Removed periods from table headers per Style Guide Rule 07.
  5. Natural Tone: Used contractions ("it’s", "won’t") for readability.
  6. Glossary Compliance: Strict adherence to terms like "App Key", "Token", and "Console".

Format preservation:

  • Code blocks and markdown structures (tables, headers) remain unchanged.
  • API links and import statements are unmodified.