Browse SDKs · iOS
Platform
SDKsiOS

Clear conversation messages

Retain a conversation entry while clearing its messages with OpenIM iOS SDK.

Copy

Invoke clearConversationAndDeleteAllMsg:onSuccess:onFailure: to delete all historical messages within a specified conversation while retaining its entry in the conversation list:

Parameters

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget conversation ID.

Code example

[[OIMManager manager] clearConversationAndDeleteAllMsg:@"c2c_user1002"
                                             onSuccess:^(NSString * _Nullable data) {
                                                 NSLog(@"clearConversationAndDeleteAllMsg success");
                                             }
                                             onFailure:^(NSInteger code, NSString *message) {
                                                 NSLog(@"clearConversationAndDeleteAllMsg failed: %ld %@", (long)code, message);
                                             }];

Return value

The onSuccess callback returns confirmation when the operation succeeds.

State changes after the call

  1. Local message and conversation update: All local historical messages in the specified conversation are cleared. The conversation's latest message preview is wiped, and its unread message count resets to 0. The conversation entry remains in the list.
  2. Event notification: Updated conversation properties are broadcast via the onConversationChanged: delegate callback. The client uses conversationID as the primary key to refresh the list cell and empty preview text.
  3. Re-query calibration: If the conversation needs full deletion alongside its message records, call Delete a conversation and its messages. For conversation listener setup, refer to Retrieve conversation list.