Initialization
Before using other features of the SDK, initialization must be performed first. This article details the initialization methods for the IMKit SDK.
For first-time users of RC, we recommend reading the IMKit SDK Quick Start guide to complete tasks like developer account registration.
Prepare 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 of your created applications from the Service Management page.
If you manage multiple applications, pay attention to selecting the correct application name (labeled as 1 in the diagram below). 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, labeled as 2 below).
- If you're not the application creator, we recommend verifying that the displayed data center matches expectations when obtaining the App Key.
- If you haven't applied for application activation with RC, only the development environment is available.
Global Data Center
- If you use the global data center with development version (dev) SDK 5.4.2 or newer, ensure you pass the correct area code (RCAreaCode) in the initialization configuration.
- If you use the global data center with stable version (stable) SDK or development version (dev) SDK earlier than 5.4.2, you must modify the IMLib SDK connection service address to the global data center address before initialization. Otherwise, the SDK defaults to connecting to the China (Beijing) Data Center service address. For details, see Configure Global Data Center Service Address.
Initialize the SDK
The following initialization methods require SDK version ≥ 5.4.2. Check the latest development (Dev) and stable (Stable) version numbers on the RC Official SDK Download Page.
Import the SDK header file:
#import <RongIMKit/RongIMKit.h>
Pass the Production or Development environment App Key in the initialization method:
NSString *appKey = @"Your_AppKey"; // example: bos9p5rlcm2ba
RCInitOption *initOption = nil;
[[RCIM sharedRCIM] initWithAppKey:appKey option:initOption];
The initialization configuration (RCInitOption
) encapsulates the area code (RCAreaCode) setting. The SDK will use the area code to obtain valid navigation service addresses, file service addresses, statistics service addresses, and log service addresses.
- If the App Key belongs to the China (Beijing) Data Center, no additional
RCInitOption
configuration is needed—the SDK will use default settings. - If using a global data center, verify the corresponding App Key in the console and configure the matching enum value from RCAreaCode.
For example, for the Singapore data center:
NSString *appKey = @"Your_AppKey"; // example: bos9p5rlcm2ba
RCInitOption *initOption = [[RCInitOption alloc] init];
initOption.areaCode = RCAreaCodeSG;
[[RCIM sharedRCIM] initWithAppKey:appKey option:initOption];
Besides the area code, InitOption
also includes these configurations:
- Navigation service address (
naviServer
): Generally not recommended for manual configuration. The SDK defaults to addresses corresponding to the area code. - File service address (
fileServer
): For private cloud use only. - Statistics service address (
statisticServer
): Generally not recommended for manual configuration.
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";
[[RCIM sharedRCIM] initWithAppKey:appKey option:initOption];
Initialize the SDK (< 5.4.2)
If using development version SDK earlier than 5.4.2 or stable version SDK 5.3.8 or earlier, use the method below. We recommend upgrading to the latest SDK version.
Import the SDK header file:
#import <RongIMKit/RongIMKit.h>
Pass the Development or Production environment App Key in the initialization method (do not mix environments):
[[RCIM sharedRCIM] initWithAppKey:@"RC AppKey"];