Browse SDKs · iOS
Platform
SDKsiOSEnterprise

Add conversations to groups

Add conversation-group relationships with Open_im_sdkAddConversationsToGroups.

Copy

Invoke Open_im_sdkAddConversationsToGroups to associate one or more conversations with specified conversation groups in a batch. This operation establishes group associations only; it does not alter conversation data or message delivery:

Parameters

ParameterTypeRequiredDescription
conversationIDsNSArray<NSString *> *YesList of conversation IDs to add into the groups.
conversationGroupIDsNSArray<NSString *> *YesList of target conversation group IDs.

Code example

#import <OpenIMSDK/CallbackProxy.h>
@import OpenIMCore;

NSData *conversationData =
    [NSJSONSerialization dataWithJSONObject:@[@"c2c_user1002"] options:0 error:nil];
NSString *conversationIDsJSON =
    [[NSString alloc] initWithData:conversationData encoding:NSUTF8StringEncoding];

NSData *groupData =
    [NSJSONSerialization dataWithJSONObject:@[@"group_work_101"] options:0 error:nil];
NSString *groupIDsJSON =
    [[NSString alloc] initWithData:groupData encoding:NSUTF8StringEncoding];

CallbackProxy *callback = [[CallbackProxy alloc]
    initWithOnSuccess:^(NSString * _Nullable data) {
        NSLog(@"AddConversationsToGroups success");
    }
    onFailure:^(NSInteger code, NSString * _Nullable message) {
        NSLog(@"AddConversationsToGroups failed: %ld %@", (long)code, message);
    }];

Open_im_sdkAddConversationsToGroups(callback, conversationIDsJSON, groupIDsJSON);

Return value

The onSuccess callback returns confirmation when the association request completes successfully.

State changes after the call

  1. Local state update: The client updates local membership records keyed by composite identifiers (conversationGroupID and conversationID).
  2. Event notification: Active client sessions receive notifications through the onConversationGroupMemberAdded: listener callback.
  3. Re-query calibration: For listener integration details, refer to Conversation groups overview.