Browse SDKs · iOS
Platform
SDKsiOSEnterprise

Load message history in reverse

Retrieve history toward newer messages from an anchor with OpenIM iOS SDK.

Copy

When navigating to a specific message via search results, notifications, or reply references, invoke getAdvancedHistoryMessageListReverse:onSuccess:onFailure: on OIMManager to load newer messages chronologically forward from that anchor message:

Parameters

ParameterTypeRequiredDescription
optsOIMGetAdvancedHistoryMessageListParam *YesQuery configuration parameters object.

Properties of OIMGetAdvancedHistoryMessageListParam

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget conversation identifier.
startClientMsgIDNSString *YesAnchor message's clientMsgID. The SDK retrieves pages of newer messages starting after this message.
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 = anchorMessage.clientMsgID;
param.count = 20;
param.viewType = OIMGetHistoryViewTypeHistory;

[[OIMManager manager] getAdvancedHistoryMessageListReverse:param
    onSuccess:^(OIMGetAdvancedHistoryMessageListInfo * _Nullable result) {
        // Append retrieved newer messages to the bottom of the list
        [self appendMessages: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 messages sorted in ascending chronological order (NSArray<OIMMessageInfo *> *).
  • isEnd: Boolean indicating whether the newest message boundary in the conversation has been reached.
  • lastMinSeq: Minimum sequence number in the current retrieved chunk.

State changes after the call

  1. Snapshot loading: Reverse pagination retrieves existing message snapshots on demand and does not trigger incoming message listeners.
  2. Scroll state coordination: Avoid mixing forward and backward pagination arbitrarily at the same scroll boundary. Deduplicate messages using clientMsgID scoped to conversationID. For standard backward history queries, see Load message history.