Browse SDKs · iOS
Platform
SDKsiOS

Insert a local one-to-one message

Insert one local one-to-one message with OpenIM iOS SDK.

Copy

Invoke insertSingleMessageToLocalStorage:recvID:sendID:onSuccess:onFailure: on OIMManager to write a custom message record (such as a local system prompt, security alert, or placeholder) directly into the local one-to-one conversation database without sending it over the network:

Parameters

ParameterTypeRequiredDescription
messageOIMMessageInfo *YesPrepared message model to be inserted locally.
recvIDNSString *YesRecipient user ID for the one-to-one chat.
sendIDNSString *YesSender user ID for the one-to-one chat.
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] insertSingleMessageToLocalStorage:message
                                                 recvID:targetUserID
                                                 sendID:currentUserID
                                              onSuccess:^(OIMMessageInfo * _Nullable stored) {
    // Local insertion succeeded; update conversation 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 conversation message cache using clientMsgID (scoped to conversationID).

State changes after the call

  1. Local-only persistence: This operation modifies local device storage only. It does not send network requests to the server, does not notify the counterparty, and does not trigger incoming message listeners (onRecvNewMessage:).
  2. Group chat insertion: To insert a local message into a group conversation, see Insert a local group message.