SDKsiOS
Retrieve a conversation by chat target
Retrieve a conversation for a user or group with OpenIM iOS SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionType | OIMConversationType | Yes | Conversation category. Pass OIMConversationTypeC2C for direct chats, or OIMConversationTypeGroup for group chats. |
sourceID | NSString * | Yes | Target entity identifier: peer user ID for direct chats, or group ID for group chats. |
Session types (OIMConversationType)
| Enum | Value | Description |
|---|---|---|
OIMConversationTypeC2C | 1 | Direct one-to-one conversation. |
OIMConversationTypeGroup | 2 | Regular group conversation. |
OIMConversationTypeSuperGroup | 3 | Large-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
conversationIDas 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).
Was this page helpful?