Skip to main content

Initialization

Before using other features of the SDK, initialization must be performed first. This article provides a detailed explanation of the initialization methods for the IMLib SDK.

For first-time users of RC, we recommend reading the IMLib SDK Quick Start Guide to complete tasks such as developer account registration.

Preparing the App Key

You must have a valid App Key to proceed with initialization.

You can log in to the RC Console and view the App Keys for your created applications on the Service Management page.

If you have multiple applications, pay attention to selecting the correct application name. Additionally, each RC application provides two independent sets of App Key / Secret for isolating production and development environments. When obtaining the App Key, ensure you distinguish between environments (Production / Development).

tip
  • If you are not the application creator, we recommend verifying that the data center displayed on the page matches your expectations when obtaining the App Key.
  • If you have not yet applied for application launch with RC, only the development environment is available.

Global Data Center

  • If you are using a global data center and the development version (dev) SDK 5.4.2 or later, ensure you pass the correct area code (RCAreaCode) in the initialization configuration.
  • If you are using a global data center with the stable version (stable) SDK or a development version (dev) SDK earlier than 5.4.2, you must modify the IMLib SDK's connection service address to the global data center address before initialization. Otherwise, the SDK will default to connecting to the China (Beijing) Data Center service address. For detailed instructions, refer to Configuring Global Data Center Service Addresses.

Initializing the SDK

tip

The following initialization methods require SDK version ≥ 5.4.2. You can check the latest development (Dev) and stable (Stable) version numbers by executing pod repo update followed by pod search RongCloudIM in Terminal to query the latest IMLib version in the CocoaPods repository.

Import the SDK header file:

#import <RongIMLib/RongIMLib.h>

Pass the App Key for either the production or development environment in the initialization method.

NSString *appKey = @"Your_AppKey"; // example: bos9p5rlcm2ba
RCInitOption *initOption = nil;

[[RCCoreClient sharedCoreClient] initWithAppKey:appKey option:initOption];

The initialization configuration (RCInitOption) encapsulates the area code (RCAreaCode) setting. The SDK will use the area code to obtain valid configurations for navigation service addresses, file service addresses, data statistics service addresses, and log service addresses.

  • If the App Key belongs to the China (Beijing) Data Center, no additional RCInitOption configuration is required, as the SDK will use all default settings.
  • If using a global data center, verify the App Key's associated data center in the console and configure the corresponding enumeration value in RCAreaCode.

For example, if using the Singapore data center, configure as follows:

NSString *appKey = @"Your_AppKey"; // example: bos9p5rlcm2ba
RCInitOption *initOption = [[RCInitOption alloc] init];
initOption.areaCode = RCAreaCodeSG;

[[RCCoreClient sharedCoreClient] initWithAppKey:appKey option:initOption];

In addition to the area code, the initialization configuration (InitOption) also encapsulates the following settings:

  • Navigation service address (naviServer): Generally not recommended for separate configuration. The SDK defaults to using the address corresponding to the area code.
  • File service address (fileServer): For private cloud use only.
  • Data statistics service address (statisticServer): Generally not recommended for separate configuration. The SDK defaults to using the address corresponding to the area code.
NSString *appKey = @"Your_AppKey"; // example: bos9p5rlcm2ba
RCInitOption *initOption = [[RCInitOption alloc] init];
initOption.areaCode = RCAreaCodeSG;
initOption.naviServer = @"http(s)://naviServer";
initOption.fileServer = @"http(s)://fileServer";
initOption.statisticServer = @"http(s)://statsServer";
[[RCCoreClient sharedCoreClient] initWithAppKey:appKey option:initOption];

Initializing the SDK (< 5.4.2)

tip

If you are using a development version SDK earlier than 5.4.2 or a stable version SDK 5.3.8 or earlier, you must use the following initialization method. We recommend upgrading to the latest SDK version as soon as possible.

Import the SDK header file:

#import <RongIMLib/RongIMLib.h>

Pass the App Key for either the production or development environment when initializing the SDK. You can use the initialization method of RCCoreClient.

[[RCCoreClient sharedCoreClient] initWithAppKey:@"RC AppKey"];