Browse SDKs · iOS
Platform
SDKsiOS

Find messages by ID

Locate messages by conversationID and clientMsgID with OpenIM iOS SDK.

Copy

By specifying a list of conversation IDs and client message IDs, invoke findMessageList:onSuccess:onFailure: on OIMManager to locate specific historical messages stored locally:

Parameters

ParameterTypeRequiredDescription
paramListNSArray<OIMFindMessageListParam *> *YesArray of search criteria models. Supports querying across multiple conversations in a single request.

Properties of OIMFindMessageListParam

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget conversation identifier.
clientMsgIDListNSArray<NSString *> *YesArray of client message IDs (clientMsgID) to look up.

Code example

OIMFindMessageListParam *query = [OIMFindMessageListParam new];
query.conversationID = conversationID;
query.clientMsgIDList = @[clientMsgID];

[[OIMManager manager] findMessageList:@[query]
    onSuccess:^(OIMSearchResultInfo * _Nullable result) {
        OIMSearchResultItemInfo *item = result.findResultItems.firstObject;
        OIMMessageInfo *message = item.messageList.firstObject;
        if (message != nil) {
            [self openMessage:message conversationID:item.conversationID];
        }
    }
    onFailure:^(NSInteger code, NSString * _Nullable msg) {
        // Handle lookup failure
    }];

Return value

The onSuccess callback delivers an OIMSearchResultInfo model containing:

  • totalCount: Total number of matching messages found across all queried conversations.
  • findResultItems: Array of conversation results (NSArray<OIMSearchResultItemInfo *> *). Each item includes conversationID and its corresponding messageList.

State changes after the call

  1. Local cache reading: This method only queries the local storage database and does not trigger incoming message listeners.
  2. Missing or deleted records: If the local database is not yet synchronized, the message was deleted, or the specified IDs do not exist, the message list will not contain those records. Always match retrieved messages by conversationID and clientMsgID rather than relying on index positions.