OpenIM SDK for uni-app / uni-app x
Integrate unix-openim-sdk into Android, iOS, and commercial HarmonyOS Apps built with uni-app or uni-app x.
OpenIM unix-openim-sdk is a native UTS plugin that provides user, friend, conversation, group, message, event, and local-database capabilities to uni-app and uni-app x Apps. The plugin owns the only OpenIM Core in the host process. Import flat functions from @/uni_modules/unix-openim-sdk; do not create an SDK instance.
Supported environments
| Host | Android | iOS | HarmonyOS |
|---|---|---|---|
| uni-app Vue 2 / Vue 3 | Supported, API 21+ | Supported, iOS 14+ | Not currently declared |
| uni-app x | Supported, API 21+ | Supported, iOS 14+ | Commercial, API 24 |
| Web / mini apps | Not supported | Not supported | Not supported |
Use the HBuilderX/uni-app 5.23 series. Android and iOS require a custom base or local native project containing the plugin's native dependencies; the standard base cannot load them.
Public and commercial capabilities
This documentation covers both public capabilities and commercial extensions. APIs, events, and fields carrying a Commercial badge require the commercial unix-openim-sdk and a matching OpenIMServer deployment. Edition and platform support are separate: a public API can still return platform-unsupported on a particular platform.
Commercial extensions include signaling, SDK session snapshots, translation, and selected message or conversation features. onSDKSessionChanged is synthesized by the plugin from initialization, login, logout, token, and account transitions. It is not a native OpenIM Core event.
Integration sequence
- Install
unix-openim-sdkand prepare a custom base or local native project. - Call
initSDK()withapiAddr,wsAddr, platform, logging, andsystemType. - Save the subscription handles returned by connection, message, and business event listeners.
- Obtain the current user's
userIDand token from a trusted backend, then calllogin(userID, token). - Wait for
onConnectSuccess, load snapshots, and apply subsequent events incrementally. - On sign-out, call
logout()and release listeners withoff(subscription). CallunInitSDK()only when the App no longer uses the SDK.
Invocation model
Promises resolve directly to business values; there is no Web SDK { data } wrapper. Event registration synchronously returns an OpenIMSDKEventSubscription:
import { off, onRecvNewMessage } from '@/uni_modules/unix-openim-sdk'
const messageSubscription = onRecvNewMessage((message) => {
console.log(message.clientMsgID)
})
off(messageSubscription)Do not use offAll() for normal scoped cleanup. It removes every listener owned by the plugin instance and is intended only for full App teardown or controlled test reset.
Security boundaries
- Obtain user tokens from a trusted backend. Never embed administrator tokens, secrets, or fixed user tokens in the App.
- Physical devices must use reachable
apiAddrandwsAddrvalues;localhostpoints to the device itself. - Do not open, move, or modify the SDK-managed database directly.
- Redact tokens, full private-message bodies, and commercial credentials from logs and reports.
- AV Runtime is a separate UTS plugin. It reuses this plugin's single login session but is not part of the public IM API.
Continue with Before you start, Install, initialize, and inspect the SDK, and Event overview.
Was this page helpful?