Monitor Connection Status
The SDK provides the IM connection status change delegate protocol RCConnectionStatusChangeDelegate
. By monitoring changes in the IM connection status, the app can handle different business processes or provide prompts on the page.
Connection Status Change Delegate Protocol
The RCConnectionStatusChangeDelegate
protocol is defined as follows:
@protocol RCConnectionStatusChangeDelegate <NSObject>
/*!
IMLib connection status listener
@param status The connection status between the SDK and RC server
@discussion If you set the IMLib connection listener, this method will be called back when the connection status between the SDK and RC server changes.
*/
- (void)onConnectionStatusChanged:(RCConnectionStatus)status;
@end
Please set the delegate object to a singleton object like AppDelegate to ensure that the delegate method can be monitored throughout the entire lifecycle of the app.
When the connection status changes, the SDK will call back the current connection status to the developer through the - (void)onConnectionStatusChanged:(RCConnectionStatus)status;
method. RCConnectionStatus defines the possible status changes during the connection process. The table below specifically explains the status codes that the app needs to handle.
Error Code | Value | Description |
---|---|---|
ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT | 6 | The current user logged in on another device, and this device was kicked offline |
ConnectionStatus_Timeout | 14 | Automatic connection timed out, the SDK will not continue to connect, the user needs to handle the timeout and then manually call the connectWithToken interface to connect |
ConnectionStatus_TOKEN_INCORRECT | 15 | The token is invalid, please obtain a new token from the app server. There are two reasons: One is that the token is incorrect, please check whether the AppKey used for client initialization is consistent with the AppKey used by the server to obtain the token; The other is that the token has expired, because the token expiration time was set in the console, and it is necessary to request the developer's server to obtain a new token and use the new token to establish a connection again. |
ConnectionStatus_DISCONN_EXCEPTION | 16 | The connection to the server has been disconnected, the user is banned |
Add or Remove Delegate
Set the connection status listener, supports setting multiple listeners.
To avoid memory leaks, please remove the set delegate when it is no longer needed.
/// Add delegate
[[RCCoreClient sharedCoreClient] addConnectionStatusChangeDelegate:self];
/// Remove delegate
[[RCCoreClient sharedCoreClient] removeConnectionStatusChangeDelegate:self];