Skip to main content

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.

tip
  • 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
import NexconnChatSDK

Pass your production or development App Key to the initialization method:

swift
import NexconnChatSDK

let params = InitParams(appKey: "Your_AppKey")
NCEngine.initialize(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 valueDescription
NCAreaCodeBjBeijing data center
NCAreaCodeSgSingapore data center (default)
NCAreaCodeNaNorth America data center
NCAreaCodeSaSaudi Arabia data center
NCAreaCodeOmOman data center

For example, to use the Singapore data center:

swift
import NexconnChatSDK

let params = InitParams(appKey: "Your_AppKey")
params.areaCode = .sg
NCEngine.initialize(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 is NCLogLevelWarn.
  • forceKeepAlive — Whether to keep the connection alive in the background. Default is NO.
  • enableSyncEmptyTopConversation — Whether to sync pinned conversations with no messages. Default is NO.
  • compressOptions — Local media compression configuration (NCCompressOptions).
swift
import NexconnChatSDK

let params = InitParams(appKey: "Your_AppKey")
params.areaCode = .sg
params.naviServer = "http(s)://naviServer"
params.logLevel = .info
NCEngine.initialize(params)

API reference

Method signature:

swift
static func initialize(_ params: InitParams)
ParameterTypeRequiredDescription
paramsNCInitParams *YesInitialization parameters. appKey is required; all other fields are optional.

NCInitParams properties:

PropertyTypeDefaultDescription
appKeyNSString *App Key assigned by Nexconn (required)
naviServerNSString *nilNavigation server URL
areaCodeNCAreaCodeNCAreaCodeSgData center area code
enableSyncEmptyTopConversationBOOLNOWhether to sync pinned conversations with no messages
compressOptionsNCCompressOptions *nilLocal media compression configuration
forceKeepAliveBOOLNOWhether to keep the connection alive in the background
logLevelNCLogLevelNCLogLevelWarnSDK log level

Usage notes:

  1. Call this method before any other SDK operations.
  2. Call it in application:didFinishLaunchingWithOptions:.
  3. You only need to call it once per app lifecycle.

Example:

swift
import NexconnChatSDK

let params = InitParams(appKey: "Your_AppKey")
NCEngine.initialize(params)