Browse SDKs · iOS
Platform
SDKsiOS

Retrieve a conversation by chat target

Retrieve a conversation for a user or group with OpenIM iOS SDK.

Copy

Retrieve a conversation snapshot for a specific user or group using getOneConversationWithSessionType:sourceID:onSuccess:onFailure:. Use this method when navigating to a chat view from a profile card or group detail screen.

Parameters

ParameterTypeRequiredDescription
sessionTypeOIMConversationTypeYesConversation category. Pass OIMConversationTypeC2C for direct chats, or OIMConversationTypeGroup for group chats.
sourceIDNSString *YesTarget entity identifier: peer user ID for direct chats, or group ID for group chats.

Session types (OIMConversationType)

EnumValueDescription
OIMConversationTypeC2C1Direct one-to-one conversation.
OIMConversationTypeGroup2Regular group conversation.
OIMConversationTypeSuperGroup3Large-scale super group conversation.

Code example

[[OIMManager manager] getOneConversationWithSessionType:OIMConversationTypeC2C
                                               sourceID:@"user_1002"
                                              onSuccess:^(OIMConversationInfo *conversation) {
                                                  [chatRouter openConversation:conversation];
                                              }
                                              onFailure:^(NSInteger code, NSString *message) {
                                                  NSLog(@"getOneConversation failed: %ld %@", (long)code, message);
                                              }];

Return value

The onSuccess callback returns a complete OIMConversationInfo object. Even if no message history exists between the participants, the SDK automatically initializes and returns a valid conversation object. Avoid manually synthesizing conversation models. To obtain only the calculated conversation identifier string locally, invoke Generate a conversation ID.

State changes after the call

  • Local state merge: Merge the returned record into active view models using conversationID as the primary key.
  • Snapshot query: This query establishes an instantaneous point-in-time snapshot and does not emit delegate callbacks.
  • Subsequent synchronization: Live conversation changes continue to arrive via OIMConversationListener (see Retrieve the conversation list).