Browse SDKs · iOS
Platform
SDKsiOS

Insert a local group message

Insert one local group message with OpenIM iOS SDK.

Copy

Invoke insertGroupMessageToLocalStorage:groupID:sendID:onSuccess:onFailure: on OIMManager to write a custom group message record (such as a local group reminder, security warning, or placeholder) directly into the local group conversation database without broadcasting it over the network:

Parameters

ParameterTypeRequiredDescription
messageOIMMessageInfo *YesPrepared message model to be inserted locally.
groupIDNSString *YesTarget group ID for the group conversation.
sendIDNSString *YesSender user ID for the group message.
onSuccessvoid (^)(OIMMessageInfo * _Nullable stored)YesSuccess callback returning the locally persisted message model.
onFailureOIMFailureCallbackYesFailure callback returning error code code and descriptive message msg.

Code example

[[OIMManager manager] insertGroupMessageToLocalStorage:message
                                               groupID:groupID
                                                sendID:currentUserID
                                             onSuccess:^(OIMMessageInfo * _Nullable stored) {
    // Local insertion succeeded; update group message list
    if (stored != nil) {
        [self upsertMessage:stored];
    }
}
                                             onFailure:^(NSInteger code, NSString * _Nullable msg) {
    // Handle insertion failure
}];

Return value

The onSuccess callback delivers the locally stored OIMMessageInfo model. When non-nil, merge it into the local group conversation cache using clientMsgID (scoped to the group's conversationID).

State changes after the call

  1. Local-only persistence: This operation mutates only the current device's SQLite database. It does not broadcast to group members, does not upload files, and does not trigger incoming message listeners (onRecvNewMessage:).
  2. One-to-one chat insertion: To insert a local message into a one-to-one conversation, see Insert a local one-to-one message.