Initialize the SDK
Initialize the Chat SDK before you use any other features. This guide explains the available initialization methods and configuration options.
If you're new to Nexconn, start with the Send your first message quickstart to register a developer account and set up your project.
Prepare your app key
You need a valid App Key to initialize the SDK.
Log in to the App Key page to find your App Key.
If you have multiple applications, select the correct app. Each application provides separate App Key and App Secret pairs for the production and development environments.
- If you are not the application creator, verify that the data center shown on the page matches your expectations.
- If your application has not been approved for production, you can only use the development environment.
Initialize
Import the SDK in Swift, or use the Objective-C header in legacy code:
- Swift
- Objective-C
import NexconnChatSDK
#import <NexconnChatSDK/NexconnChatSDK.h>
Pass your production or development App Key to the initialization method:
- Swift
- Objective-C
import NexconnChatSDK
let params = InitParams(appKey: "Your_AppKey")
NCEngine.initialize(params)
NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"Your_AppKey"];
[NCEngine initializeWithParams:params];
Configure the data center
NCInitParams includes an areaCode property (NCAreaCode) that determines the navigation server and related endpoint URLs.
Check which data center your App Key belongs to in the Console, then set the corresponding NCAreaCode enum value.
NCAreaCode value | Description |
|---|---|
NCAreaCodeBj | Beijing data center |
NCAreaCodeSg | Singapore data center (default) |
NCAreaCodeNa | North America data center |
NCAreaCodeSa | Saudi Arabia data center |
NCAreaCodeOm | Oman data center |
For example, to use the Singapore data center:
- Swift
- Objective-C
import NexconnChatSDK
let params = InitParams(appKey: "Your_AppKey")
params.areaCode = .sg
NCEngine.initialize(params)
NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"Your_AppKey"];
params.areaCode = NCAreaCodeSg;
[NCEngine initializeWithParams:params];
Advanced configuration
NCInitParams also supports the following properties:
naviServer— Navigation server URL. We don't recommend setting this manually. By default, the SDK uses the URL associated with the selected area code.logLevel— SDK log level (NCLogLevel). Default isNCLogLevelWarn.forceKeepAlive— Whether to keep the connection alive in the background. Default isNO.enableSyncEmptyTopConversation— Whether to sync pinned conversations with no messages. Default isNO.compressOptions— Local media compression configuration (NCCompressOptions).
- Swift
- Objective-C
import NexconnChatSDK
let params = InitParams(appKey: "Your_AppKey")
params.areaCode = .sg
params.naviServer = "http(s)://naviServer"
params.logLevel = .info
NCEngine.initialize(params)
NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"Your_AppKey"];
params.areaCode = NCAreaCodeSg;
params.naviServer = @"http(s)://naviServer";
params.logLevel = NCLogLevelInfo;
[NCEngine initializeWithParams:params];
API reference
Method signature:
- Swift
- Objective-C
static func initialize(_ params: InitParams)
+ (void)initializeWithParams:(NCInitParams *)params
| Parameter | Type | Required | Description |
|---|---|---|---|
| params | NCInitParams * | Yes | Initialization parameters. appKey is required; all other fields are optional. |
NCInitParams properties:
| Property | Type | Default | Description |
|---|---|---|---|
appKey | NSString * | — | App Key assigned by Nexconn (required) |
naviServer | NSString * | nil | Navigation server URL |
areaCode | NCAreaCode | NCAreaCodeSg | Data center area code |
enableSyncEmptyTopConversation | BOOL | NO | Whether to sync pinned conversations with no messages |
compressOptions | NCCompressOptions * | nil | Local media compression configuration |
forceKeepAlive | BOOL | NO | Whether to keep the connection alive in the background |
logLevel | NCLogLevel | NCLogLevelWarn | SDK log level |
Usage notes:
- Call this method before any other SDK operations.
- Call it in
application:didFinishLaunchingWithOptions:. - You only need to call it once per app lifecycle.
Example:
- Swift
- Objective-C
import NexconnChatSDK
let params = InitParams(appKey: "Your_AppKey")
NCEngine.initialize(params)
NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"Your_AppKey"];
[NCEngine initializeWithParams:params];