Browse SDKs · uni-app / uni-app x
SDKsuni-app

Install, initialize, and inspect the SDK

Install the UTS plugin, initialize the only OpenIM Core, and inspect version and data paths.

Copy

After installing uni_modules/unix-openim-sdk, initialize it once from an application service. The plugin exports flat functions; do not construct a second SDK instance.

import {
  OpenIMLogLevelInfo,
  OpenIMPlatformAndroid,
  initSDK,
  type OpenIMInitConfig,
} from '@/uni_modules/unix-openim-sdk'

const config : OpenIMInitConfig = {
  platformID: OpenIMPlatformAndroid,
  apiAddr: 'https://im-api.example.com',
  wsAddr: 'wss://im-ws.example.com',
  logLevel: OpenIMLogLevelInfo,
  isLogStandardOutput: true,
  systemType: 'android',
}

const initialized = await initSDK(config)
if (!initialized) throw new Error('OpenIM SDK initialization was not accepted')

Use OpenIMPlatformIOS with systemType: 'ios', or OpenIMPlatformHarmony with systemType: 'harmony'. Reduce console logging in production and configure logFilePath according to your compliance policy.

OpenIMInitConfig fieldTypeDescription
platformIDOpenIMPlatformOne of the exported platform constants.
apiAddrstringOpenIMServer HTTP API address.
wsAddrstringOpenIMServer WebSocket address.
dataDirstring or null (optional)Core data directory; normally use the platform default.
logFilePathstring or null (optional)Log path following the platform artifact contract.
logLevelOpenIMLogLevelFor example OpenIMLogLevelError or OpenIMLogLevelInfo.
isLogStandardOutputbooleanWhether SDK logs are emitted to the system console.
systemTypestringRequired system description; never omit it.

Do not initialize concurrent environments in one process. Sign out, clear application state, and uninitialize before changing service addresses.

getSdkVersion() and getOpenIMDataPath() are synchronous local operations:

import { getOpenIMDataPath, getSdkVersion } from '@/uni_modules/unix-openim-sdk'

const version = getSdkVersion()
const dataPath = getOpenIMDataPath()

Use the data path only for diagnostics and storage policy. Never edit the SDK database or publish full sandbox paths in logs.

import { unInitSDK } from '@/uni_modules/unix-openim-sdk'

unInitSDK()

unInitSDK() returns void. Stop new requests, sign out, and release subscriptions first. Page unload, App backgrounding, and AV Runtime disposal must not uninitialize the IM SDK.