Skip to main content

initSDK

Description

info

Initialization is the first step for the client to call the SDK. It can only be called once during the application's lifecycle. Repeated calls may lead to unknown issues.

Note

(1) After successful initialization, set various listeners and log in. Ensure that other APIs are called after the synchronous login callback is completed. There are examples of specific flows in the Quick Start for each platform;
(2) The client's underlying logs will be stored in a specified directory for debugging, but it is not recommended to enable this in a production environment.

Function Prototype

- (BOOL)initSDKWithConfig:(OIMInitConfig *)config
onConnecting:(nullable OIMVoidCallback)onConnecting
onConnectFailure:(nullable OIMFailureCallback)onConnectFailure
onConnectSuccess:(nullable OIMVoidCallback)onConnectSuccess
onKickedOffline:(nullable OIMVoidCallback)onKickedOffline
onUserTokenExpired:(nullable OIMVoidCallback)onUserTokenExpired;

Input Parameters

Parameter NameParameter TypeRequiredDescription
configOIMInitConfigYesInitialization parameter

Return Result

NameTypeDescription
successBOOLIdentifies whether initialization is successful
onConnectingOIMVoidCallbackConnecting callback
onConnectFailureOIMFailureCallbackConnection failure callback
onConnectSuccessOIMFailureCallbackConnection success callback
onKickedOfflineOIMVoidCallbackKicked offline callback
onUserTokenExpiredOIMVoidCallbacktoken expired callback

Code Example

OIMInitConfig *config = [OIMInitConfig new];
config.apiAddr = @"";
config.wsAddr = @"";
config.objectStorage = @"";

BOOL success = [OIMManager.manager initSDKWithConfig:config
onConnecting:^{

} onConnectFailure:^(NSInteger code, NSString * _Nullable msg) {
// Connection failed callback function
// code error code
// error error message
} onConnectSuccess:^{
// SDK has successfully connected to the IM server
} onKickedOffline:^{
// SDK is connecting to the IM server
} onUserTokenExpired:^{
// Ticket expired while online: at this point you need to generate a new token and call the login() function again to re-login.
}];