SDKsiOS
Find messages by ID
Locate messages by conversationID and clientMsgID with OpenIM iOS SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
paramList | NSArray<OIMFindMessageListParam *> * | Yes | Array of search criteria models. Supports querying across multiple conversations in a single request. |
Properties of OIMFindMessageListParam
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | NSString * | Yes | Target conversation identifier. |
clientMsgIDList | NSArray<NSString *> * | Yes | Array 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 includesconversationIDand its correspondingmessageList.
State changes after the call
- Local cache reading: This method only queries the local storage database and does not trigger incoming message listeners.
- 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
conversationIDandclientMsgIDrather than relying on index positions.
Was this page helpful?