OpenIM HarmonyOS SDK overview
Integrate OpenIMClientSDK into HarmonyOS phones, tablets, and 2in1 devices.
The OpenIM HarmonyOS SDK is designed specifically for the HarmonyOS ecosystem, providing type-safe native ArkTS APIs powered by a high-performance cross-platform core engine via N-API. By adding the HAR package, you can implement user profiles, relationship chains, conversation lists, group management, message transmission, local persistence storage, audio and video call signaling, and real-time event listeners.
Scope and support
The HarmonyOS SDK supports the following device categories and native architectures:
| Device type | Support status | Native architecture |
|---|---|---|
| Phone | Supported | arm64-v8a |
| Tablet | Supported | arm64-v8a |
| 2in1 | Supported | x86_64, arm64-v8a |
All three device categories share Platform.HarmonyOS, eliminating the need to maintain different business APIs across form factors. Multi-window 2in1 applications should maintain the SDK instance and database directory at the application process level; closing an individual window does not destroy the SDK instance.
The HarmonyOS SDK is a commercial delivery feature. Consult your commercial agreement and provided HAR package for specific distribution artifacts, license scopes, and enterprise capabilities.
SDK entry point
The SDK exports a default process-level instance:
import sdk, { OpenIMSDKEvent } from '@openimsdk/imsdk';- Asynchronous APIs return Promises that resolve directly to the declared response object without an extra
{ data }wrapper. - When an API call fails, the Promise rejects with an error object containing
errCodeanderrMsgto differentiate parameter, network, and server-side errors. sdk.on()returns an unsubscribe function. Query APIs fetch initial data snapshots, while event listeners merge incremental updates in real time. During weak network reconnection or unexpected state drift, query again to reconcile local data.- Local databases, logs, and media files must use valid, writable or readable paths within the application sandbox.
Recommended integration workflow
- Review Before you start to set up OpenIMServer, prepare login credentials, and configure DevEco Studio.
- Follow Environment-specific implementation to install the HAR, declare required permissions, and initialize the SDK.
- Register connection and synchronization listeners before logging in, then follow Authenticate and manage session to log in.
- Wait for the connection to succeed and server data synchronization to finish, then follow Send your first message to verify message transmission.
The recommended lifecycle order is: Initialize the SDK (Environment-specific implementation) -> Register event listeners -> Log in (Authenticate and manage session) -> Await connection success and server synchronization -> Invoke business APIs.
Was this page helpful?