Browse SDKs · iOS
Platform
SDKsiOS

Load message history

Retrieve conversation history by page with OpenIM iOS SDK.

Copy

When entering a conversation or pulling down to view earlier messages, invoke getAdvancedHistoryMessageList:onSuccess:onFailure: on OIMManager to query history paginated backward in time:

Parameters

ParameterTypeRequiredDescription
optsOIMGetAdvancedHistoryMessageListParam *YesQuery configuration parameters object.

Properties of OIMGetAdvancedHistoryMessageListParam

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget conversation identifier.
startClientMsgIDNSString * _NullableNoClient message ID (clientMsgID) of the pagination anchor message. Pass nil for the initial page of latest history; pass the topmost message's clientMsgID when loading earlier messages.
countNSIntegerYesMaximum number of messages to retrieve per page.
viewTypeOIMGetHistoryViewTypeYesHistory query view type (typically OIMGetHistoryViewTypeHistory).

Code example

OIMGetAdvancedHistoryMessageListParam *param = [OIMGetAdvancedHistoryMessageListParam new];
param.conversationID = conversationID;
param.startClientMsgID = startClientMsgID;
param.count = 20;
param.viewType = OIMGetHistoryViewTypeHistory;

[[OIMManager manager] getAdvancedHistoryMessageList:param
    onSuccess:^(OIMGetAdvancedHistoryMessageListInfo * _Nullable result) {
        // Prepend retrieved messages and update pagination boundaries
        [self prependMessages:result.messageList ?: @[]];
    }
    onFailure:^(NSInteger code, NSString * _Nullable msg) {
        // Handle retrieval failure
    }];

Return value

The onSuccess callback delivers an OIMGetAdvancedHistoryMessageListInfo instance containing:

  • messageList: Array of retrieved OIMMessageInfo models (NSArray<OIMMessageInfo *> *).
  • isEnd: Boolean indicating whether the beginning of conversation history has been reached. When YES, stop further backward pagination.
  • lastMinSeq: Minimum sequence number in the current retrieved chunk.

State changes after the call

  1. Snapshot establishment: History queries establish or extend the local message snapshot. Calling this method does not trigger incoming message event listeners.
  2. Deduplication: Retrieved historical messages may overlap with messages received via real-time listeners. Merge items into the UI list idempotently using clientMsgID scoped to conversationID.
  3. Forward pagination: If you need to retrieve messages moving forward from a specific historical anchor, see Load message history in reverse.