SDKsuni-app
Receive custom business messages
OpenIM uni-app / uni-app x SDK guide for Receive custom business messages.
These listeners deliver opaque JSON strings. onRecvCustomBusinessMessage is public; four extension/KV listeners are Commercial and unsupported on HarmonyOS.
import { off, onRecvCustomBusinessMessage } from '@/uni_modules/unix-openim-sdk'
function handleRawPayload(payload : string) {
try {
const value = JSON.parseObject<UTSJSONObject>(payload)
if (value != null) routeValidatedBusinessEvent(value)
} catch (_) {
console.error('Invalid custom message event')
}
}
const customSubscription = onRecvCustomBusinessMessage(handleRawPayload)
off(customSubscription)uni-app JavaScript should use protected JSON.parse. Validate version, kind, and required fields before updating state, safely ignore unknown payloads, and never log the complete string.
Was this page helpful?