Browse SDKs · iOS
Platform
SDKsiOS

Receive custom business messages

Register and remove the custom-business notification listener in OpenIM iOS SDK.

Copy

The custom business message listener receives server-pushed business notifications or custom signaling data. Unlike custom chat messages delivered within regular conversations, these notifications are typically used for audio/video room signaling, real-time control directives, or custom cross-device state synchronization.

Register and remove the listener

Retain a strong reference to your OIMCustomBusinessListener instance in your state management layer, and unregister it when the session ends or during logout:

// Register the custom business message listener
[[OIMManager callbacker] addCustomBusinessListener:businessListener];

// Remove the listener when destroying components or signing out
[[OIMManager callbacker] removeCustomBusinessListener:businessListener];

Event callback handling

In your class conforming to OIMCustomBusinessListener, implement the message reception callback:

- (void)onRecvCustomBusinessMessage:(NSString * _Nullable)businessMessage {
    if (businessMessage.length == 0) {
        return;
    }
    // Parse business JSON payload and dispatch accordingly
}

State changes after the call

  1. Payload verification: The message string supplied to the callback may be nil or empty. Validate the JSON protocol version, message type, and mandatory fields before consumption.
  2. Idempotency handling: Process business actions using application-level idempotency identifiers (such as a business transaction ID or serial number) to prevent duplicate execution.
  3. Regular custom messages: Custom messages sent within regular conversations (such as red packets, stickers, or contact cards) arrive through the standard message listener instead. See Receive messages.