Browse SDKs · iOS
Platform
SDKsiOS

Delete a local message

Delete one message from the current device only with OpenIM iOS SDK.

Copy

Invoke deleteMessageFromLocalStorage:clientMsgID:onSuccess:onFailure: on OIMManager to remove a single message from the current device's local database without contacting the server or affecting other devices:

Parameters

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget conversation identifier.
clientMsgIDNSString *YesClient message ID of the message to delete.
onSuccessOIMSuccessCallbackYesSuccess callback confirming local deletion.
onFailureOIMFailureCallbackYesFailure callback returning error code code and descriptive message msg.

Code example

[[OIMManager manager] deleteMessageFromLocalStorage:conversationID
                                        clientMsgID:clientMsgID
                                          onSuccess:^(NSString * _Nullable data) {
    // Local deletion succeeded; update message list UI
    [self removeMessageFromUI:clientMsgID];
}
                                          onFailure:^(NSInteger code, NSString * _Nullable msg) {
    // Handle local deletion failure
}];

Return value

The onSuccess callback confirms that the message was removed from local storage on the current device.

State changes after the call

  1. Local-only removal: This method deletes the record from the current device's SQLite database only. Server roaming records remain intact; if the user clears app data or rebuilds the local database, the message may be synchronized again.
  2. No remote events: This is a purely local operation that does not emit events to other devices or conversation participants. The client merge key is clientMsgID scoped to conversationID. To delete a message across both local storage and the server, see Delete a message.