SDKsiOS
Insert a local one-to-one message
Insert one local one-to-one message with OpenIM iOS SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
message | OIMMessageInfo * | Yes | Prepared message model to be inserted locally. |
recvID | NSString * | Yes | Recipient user ID for the one-to-one chat. |
sendID | NSString * | Yes | Sender user ID for the one-to-one chat. |
onSuccess | void (^)(OIMMessageInfo * _Nullable stored) | Yes | Success callback returning the locally persisted message model. |
onFailure | OIMFailureCallback | Yes | Failure 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
- 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:). - Group chat insertion: To insert a local message into a group conversation, see Insert a local group message.
Was this page helpful?