SDKsiOSEnterprise
Delete messages in batches
Delete multiple messages from one conversation with OpenIM iOS SDK.
Invoke deleteMessages:clientMsgID:isSync:onSuccess:onFailure: on OIMManager to delete multiple historical messages from a single conversation in one batch, with optional cross-device synchronization for the current account:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | NSString * | Yes | Target conversation identifier. |
clientMsgID | NSArray<NSString *> * | Yes | Array of client message IDs to delete. All specified IDs must belong to the same conversation. |
isSync | BOOL | Yes | Whether to synchronize the deletion status to the current account's other online devices. |
onSuccess | OIMSuccessCallback | Yes | Success callback confirming batch deletion. |
onFailure | OIMFailureCallback | Yes | Failure callback returning error code code and descriptive message msg. |
Code example
[[OIMManager manager] deleteMessages:conversationID
clientMsgID:selectedClientMsgIDs
isSync:YES
onSuccess:^(NSString * _Nullable data) {
// Local deletion succeeded; remove items from UI
[self removeMessagesByIDs:selectedClientMsgIDs];
}
onFailure:^(NSInteger code, NSString * _Nullable msg) {
// Handle batch deletion failure
}];Return value
The onSuccess callback confirms that the batch deletion request completed.
Listen for message deletion events
When the current account deletes messages on another device with isSync enabled, the SDK notifies the local client via onMsgDeleted: in OIMAdvancedMsgListener:
- (void)onMsgDeleted:(OIMMessageInfo *)message {
if (message.clientMsgID.length == 0) {
return;
}
// Remove the message idempotently from local data sources by clientMsgID
[self removeMessageByClientMsgID:message.clientMsgID];
}State changes after the call
- Account-scoped deletion: Deleting messages removes them for the current account only; counterparty copies remain unaffected.
- Client merge key: The merge key is
clientMsgID(scoped toconversationID). Remove items idempotently from local caches upon callback success or when receivingonMsgDeleted:. - Single message deletion: For deleting a single message, see Delete a message. For full listener setup, see Receive messages.
Was this page helpful?