Manage groups

Update time: 2023/02/09 14:18:45

NIM SDK allows you to manage advanced groups, such as creating, joining, and leaving groups, transferring the ownership of a group, querying group information, and dismissing a group.

The NIMTeamManager protocol offers methods used to manage groups. The NIMTeamManagerDelegate delegate protocol contains callbacks for group events.

Listeners for group events

You can register listeners for group events before group operations. If listeners are registered, you can receive notifications for corresponding group operations.

You can register the following callbacks as required.

Add listeners for group events by calling addDelegate:.

Sample code:

/// The custom class implements the NIMTeamManagerDelegate interface

/// Group delegate interface declaration
/// NIMTeamAdapter.h
@interface NIMTeamAdapter :NSObject<NIMTeamManagerDelegate>

@end

/// Group delegate interface implementation
/// NIMTeamAdapter.m
@implementation NIMTeamAdapter
/// Callback for updating group information
- (void)onTeamUpdated:(NIMTeam *)team {
    NSLog(@"[On team updated, teamId: %@]", [team teamId]);
}
@end
...

/// main.m
/// instantiate the class
static NIMTeamAdapter *adpater;
adpater = [[NIMTeamAdapter alloc] init];
/// Add the group delegate
[[[NIMSDK sharedSDK] teamManager] addDelegate:adpater];
/// Update the group profile and trigger the delegate
// [[[NIMSDK sharedSDK] teamManager] updateTeamName:@"TestDelegate"
//                                           teamId:@"6271272396"
//                                       completion:nil];

To cancel the listener, call removeDelegate:.

Workflow

This document introduces the implementation process of group management by taking the interaction among group owners, administrators, and regular members.

uml diagram

Create a group

Create a group by calling the createTeam:users:completion: method and the creator becomes the group owner.

option:

Parameter Description
name Group name
type Group type. NIMTeamTypeAdvanced indicates an advanced group.
avatarUrl The avatar of a group
intro Group introduction
announcement Group announcement
clientCustomInfo Client custom information
postscript Additional message
joinMode Authentication mode
NIMTeamJoinModeNoAuth: No authentication is required. Everyone is allowed to join a group
NIMTeamJoinModeNeedAuth: The verification is required to join a group
NIMTeamJoinModeRejectAll: No one is allowed to join a group.
inviteMode The permission to invite people to join a group.
NIMTeamInviteModeManager: only the group owner and administrators can invite people to join a group.
NIMTeamInviteModeAll: everyone in the group can invite people to join the group.
beInviteMode acceptance mode
NoAuth: No verification required
NeedAuth: The verification from the invited people is required.
updateInfoMode The permission to edit group information.
·NIMTeamUpdateInfoModeManager·: Only the group owner and administrators can edit the group information
·NIMTeamUpdateInfoModeAll·: Everyone can edit the group information.
updateClientCustomMode Permission to edit the client custom group information
NIMTeamUpdateClientCustomModeManager: administrators
NIMTeamUpdateClientCustomModeAll: everyone
maxMemberCountLimitation The maximum number of people in a group
antispamBusinessId Business ID that requires content moderation

** Sample code:**

NIMCreateTeamOption *option = [NIMCreateTeamOption new];
    [option setName:@"a created group chat"];
    [option setType:NIMTeamTypeAdvanced];
    [option setIntro:@"Introduction"];
    /// users List of user accids
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"user01", @"user02", nil];
    /// completion Callback for completion
    NIMTeamCreateHandler completion = ^(NSError * __nullable error,
                                        NSString * __nullable teamId,
                                        NSArray<NSString *> * __nullable failedUserIds)
    {
        if (error == nil) {
            /// A group is created successfully
            NSLog(@"[Create team succeeded, teamId: %@]", teamId);
            /// your code ...
        } else {
            /// Failed to create a group
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Create a group
    [[[NIMSDK sharedSDK] teamManager] createTeam:option users:users completion:completion];

Join a group

You can join a group using the following methods:

  • Accepts the invitation to join a group.
  • Request to join a group

Invite users to join a group

The permission to invite to the group can be defined by InviteMode. If you set the value to NIMTeamInviteModeManager, only the group owner and administrator can invite people to join a group. The NIMTeamInviteModeAll allows all members in the group can invite people to join the group.

Invite other users to the group by calling addUsers:toTeam:postscript:attach:completion:.

  • If the invitation mode beInviteMode of the group is NIMTeamBeInviteModeNoAuth, users can join the group without verification.
  • If the invitation mode beInviteMode of the group is set to NIMTeamBeInviteModeNeedAuth, the invited user must agree to join the group.

If an invited member has reached the upper limit of joined groups, the accounts failing to join the group are returned.

Parameters:

Parameter Description
teamId group ID
users Accounts to be invited.
attach Custom extension field. Ignore the extension if not required. The field can contain up to 512 characters.
postscript additional message for invitation. Ignore it if not required.
completion Callback for completion
  • After the invitation is sent, the invited user will receive a NIMSystemNotification system notification of NIMSystemNotificationTypeTeamInvite type. In the notification, you can get the ID of the inviter, the ID of the group, and the additional message attached to the invitation.
  • The invited user can call acceptInviteWithTeam to accept the invitation to join the group. All group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeAcceptInvitation|
  • The invited user can also call the rejectInviteWithTeam method to reject the invitation. If the invited user rejects the invitation, the user will receive a system notification NIMSystemNotification of NIMSystemNotificationTypeTeamApplyReject type.

** Sample code:**

 /// users List of accounts to be invited
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"ios01", @"ios02", nil];
    /// teamId  Group ID
    NSString *teamId = @"6271272396";
    /// postscript additional message, optional
    NSString *postscript = @” invite you to join the group";
    /// attach extension message, optional
    NSString *attach = @"extension message";
    /// completion Callback for completion
    NIMTeamMemberHandler completion = ^(NSError * __nullable error, NSArray<NIMTeamMember *> * __nullable members)
    {
        if (error == nil) {
            /// `members` The list of members that join a group successfully
            NSLog(@"[Add %lu users to team: %@ succeed]", (unsigned long)[members count], teamId);
            /// your code ...
        } else {
            /// Failed to join the group
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Invite users to join a group
    [[[NIMSDK sharedSDK] teamManager] addUsers:users
                                        toTeam:teamId
                                    postscript:postscript
                                        attach:attach
                                    completion:completion];

//Accept an invitation
    NSString *teamId = @"6271272396";
    /// invitorId The ID of a member sending the invitation
    NSString *invitorId = @"ios02";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Join a group by accepting the invitation
            NSLog(@"[Accept invite of invitor: %@ in team: %@ succeed.]", invitorId, teamId);
            /// your code ...
        } else {
            /// Failed to join a group
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Accept an invitation to join a group
    [[[NIMSDK sharedSDK] teamManager] acceptInviteWithTeam:teamId
                                                 invitorId:invitorId
                                                completion:completion];


//Reject the invitation
    NSString *teamId = @"6271272396";
    /// invitorId The ID of a member sending the invitation
    NSString *invitorId = @"ios02";
    /// rejectReason Reason for rejecting the invitation
    NSString *rejectReason = @"Do not want to join the group";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Reject a join group request
            NSLog(@"[Reject invite of invitor: %@ in team: %@ succeed.]", invitorId, teamId);
            /// your code ...
        } else {
            /// Failed to reject a join group request
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Reject an invitation to join a group
    [[[NIMSDK sharedSDK] teamManager] rejectInviteWithTeam:teamId
                                                 invitorId:invitorId
                                              rejectReason:rejectReason
                                                completion:completion];

Request to join a group

Request to join a group by calling applyToTeam:message:completion:.

  • If the option for joinMode is NIMTeamJoinModeNoAuth, users can join the group without verification.
  • If the option for joinMode is set to NIMTeamJoinModeNeedAuth, the group owner or administrators must approve the request to join the group.
  • If the option for joinMode is NIMTeamJoinModeRejectAll, the group does not accept requests. Users can only join the group by invitation.

Parameters:

Parameter Description
teamId group ID
message Additional message for a request
completion Callback for completion
  • If a user send a join request, the group owner and administrators will receive a NIMSystemNotification system notification of NIMSystemNotificationTypeTeamApply type.
  • The group owner and administrators can approve the request by calling passApplyToTeam. All group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeApplyPass|
  • The group owner and administrators can also call the rejectApplyToTeam method to reject the request. If the invited user rejects the invitation, the user will receive a system notification NIMSystemNotification of NIMSystemNotificationTypeTeamApplyReject type.

** Sample code:**

    NSString *teamId = @"6271272396";
    /// message  Additional message for a request
    NSString *message = @"I want to join the group";
    /// completion Callback for completion
    NIMTeamApplyHandler completion = ^(NSError * __nullable error, NIMTeamApplyStatus applyStatus)
    {
        if (error == nil) {
            /// Success
            NSLog(@"[Apply to team: %@ succeed, apply status: %ld]", teamId,(long)applyStatus);
            /// your code ...
        } else {
            /// Failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Request to join a group
    [[[NIMSDK sharedSDK] teamManager] applyToTeam:teamId
                                          message:message
                                       completion:completion];


  // Approve the request
    NSString *teamId = @"6271272396";
    /// userId The ID of a user send a request
    NSString *userId = @"ios02";
    /// completion Callback for completion
    NIMTeamApplyHandler completion = ^(NSError * __nullable error, NIMTeamApplyStatus applyStatus)
    {
        if (error == nil) {
            /// Success
            NSLog(@"[Pass apply in team: %@ of user: %@ succeed, apply status: %ld]", teamId, userId, (long)applyStatus);
            /// your code ...
        } else {
            /// Failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Approve a request
    [[[NIMSDK sharedSDK] teamManager] passApplyToTeam:teamId
                                               userId:userId
                                           completion:completion];


  // Reject the request
    NSString *teamId = @"6271272396";
    /// userId The ID of a user send a request
    NSString *userId = @"ios02";
    /// rejectReason Reason for rejecting a request
    NSString *rejectReason = @"decline the request";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Reject apply in team: %@ of user: %@ succeed]", teamId, userId);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Reject a request
    [[[NIMSDK sharedSDK] teamManager] rejectApplyToTeam:teamId
                                                 userId:userId
                                           rejectReason:rejectReason
                                             completion:completion];

Transfer the ownership of a group

Only the group owner has the permission to transfer the ownership of a group.

Transfer the ownership of a group by calling transferManagerWithTeam:newOwnerId:isLeave:completion:.

  • After the ownership of the group is transferred. All group members will receive a notification of NIMMessageTypeNotification and the trigger event is NIMTeamOperationTypeTransferOwner.
  • If the group owner leaves the group while transferring the ownership, call quitTeam to leave the group. All group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeLeave|
  • After the user successfully leaves the group, the relevant session information will still be retained, but the messages from this group will no longer be received.

Parameters:

Parameter Description
teamId Group ID
newOwnerIdt Account of the new owner
isLeave Whether to leave the group while transferring the group
true: leave the group.
false: do not leave the group and the role becomes a regular group member
completion Callback for completion

** Sample code:**

NSString *teamId = @"6271272396";
    /// newOwnerId The ID of the new group owner
    NSString *newOwnerId = @"ios02";
    /// Whether the original group owner leaves the group
    BOOL isLeave = YES;
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Success
            NSLog(@"[Transfer manager to new owner: %@ succeed.]", newOwnerId);
            /// your code ...
        } else {
            /// Failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Transfer the ownership of a group
    [[[NIMSDK sharedSDK] teamManager] transferManagerWithTeam:teamId
                                                   newOwnerId:newOwnerId
                                                      isLeave:isLeave
                                                   completion:completion];

Leave a group

You can leave a group using the following methods:

  • You are removed by the group owner or group administrator.
  • You leave the group.

Remove a member from a group

  • Only the owner and moderators can remove members from the group.
  • Administrators cannot remove group owners or other administrators from a group.

Remove a member from a group by calling the kickUsers:fromTeam:completion: method.

  • After a member is removed, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeKick.
  • After the user successfully is removed the group, the relevant session information will still be retained, but the messages from this group will no longer be received.

Parameters:

Parameter Description
teamId group ID
users The members to be removed.
completion Callback for completion

** Sample code:**

/// users The members to be removed
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"ios02", nil];
    /// teamId Group ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Kick users from team: %@ succeed]", teamId);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Remove a member from a group
    [[[NIMSDK sharedSDK] teamManager] kickUsers:users
                                       fromTeam:teamId
                                     completion:completion];

Leave a group

Leave a group by calling the quitTeam:completion: method.

  • Except the group owner, all other members can leave a group. Aftare a member leaves a group, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeLeave.
  • After the user successfully leaves the group, the relevant session information will still be retained, but the messages from this group will no longer be received.

** Sample code:**

/// teamId Group ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Quit team succeeded, teamId: %@]", teamId);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Leave a group. Note: the group owner must transfer the ownership of the group owner before leaving.
    [[[NIMSDK sharedSDK] teamManager] quitTeam:teamId
                                    completion:completion];

Dismiss a group

Only the group owner have the permission to dismiss a group.

Dismiss a group by calling the dismissTeam:completion: method.

After a group is dismissed, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeDismiss.

After the group is dismissed, all conversations about this group will be retained, but all members cannot send and receive messages in this group chat.

** Sample code:**

/// teamId Group ID
    NSString *teamId = @"6271321659";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Dismiss team succeeded, teamId: %@]", teamId);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Dismiss a group
    [[[NIMSDK sharedSDK] teamManager] dismissTeam:teamId
                                       completion:completion];

Edit the group profile

Members must have permissions for editing group profiles. If the edit permission of the group profile (updateInfoMode) is set to NIMTeamUpdateInfoModeManager, only the group owner and administrators can edit the group profile. If the value is set to NIMTeamUpdateInfoModeAll, all group members can edit the group information.

Editable group attributes: group name, group avatar, introduction, announcement, verification method, invitation mode, acceptance mode, mute mode, edit permission, edit permission for custom information, and custom information.

If a user update the group information, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeUpdate.

Edit the field of a group profile

Methods used to update group properties.

Attribute Method Description
Group name updateTeamName:teamId:completion: -
Group avatar updateTeamAvatar:teamId:completion: Set the avatar of a group. If the avatar resource is uploaded to the CommsEase server, use the NOS service
Group Introduction updateTeamIntro:teamId:completion: -
Announcement updateTeamAnnouncement:teamId:completion: -
Verification method updateTeamJoinMode:teamId:completion: verification method
NIMTeamJoinModeNoAuth: No authentication is required. Everyone is allowed to join a group
NIMTeamJoinModeNeedAuth: The verification is required to join a group
NIMTeamJoinModeRejectAll: No one is allowed to join a group.
Acceptance mode updateTeamBeInviteMode:teamId:completion: NIMTeamBeInviteModeNoAuth: No verification required
NIMTeamBeInviteModeNeedAuth: The verification from the invited people is required
Invitation mode updateTeamInviteMode:teamId:completion: NIMTeamInviteModeManager: only the group owner and administrators can invite people to join a group.
NIMTeamInviteModeAll: everyone in the group can invite people to join the group
The permission to edit group information updateTeamUpdateInfoMode:teamId:completion: NIMTeamUpdateInfoModeManager: Only the group owner and administrators can edit the group information
NIMTeamUpdateInfoModeAll·: Everyone can edit the group information.
Permission to edit the client custom group information updateTeamUpdateClientCustomMode:teamId:completion: NIMTeamUpdateClientCustomModeManager: administrators have the permission.
NIMTeamUpdateClientCustomModeAll : everyone has the permission.
Group Custom Information updateTeamCustomInfo:teamId:completion: The SDK provides an extension interface for group information. You can add custom information for groups.

The following sample code is ued to edit the group name.

 /// teamName The group name to be updated
    NSString *teamName = @"updated group name";
    /// teamId The ID of a group whose name is to be updated
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Update team name to: %@ succeed]", teamName);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the name of a group
    [[[NIMSDK sharedSDK] teamManager] updateTeamName:teamName
                                              teamId:teamId
                                          completion:completion];

Edit multiple fields of a group profile

Edit multiple fields of a group profile by calling the updateTeamInfos:teamId:completion: method.

Parameters:

Parameter Description
teamId group ID
Values Group properties to be updated.
completion Callback for completion

The key-value pair arguments {@(NIMTeamUpdateTag) : NSString}. Invalid data will be filtered. For more information, see NIMTeamUpdateTag.

** Sample code:**

NSDictionary<NSNumber *,NSString *> *values = @{
        @(NIMTeamUpdateTagName):@"group name",
        @(NIMTeamUpdateTagIntro):@"introduction",
        @(NIMTeamUpdateTagAnouncement):@"announcement"
    };
    /// teamId Group ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Update team infos to: %@ succeed]", values[@(NIMTeamUpdateTagName)]);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the group profile
    [[[NIMSDK sharedSDK] teamManager] updateTeamInfos:values
                                                teamId:teamId
                                            completion:completion];
Interface:

Edit the local group profile

Edit the local group information by calling the updateTInfosLocal: method. The updated group information will not be synchronized to the server.

** Sample code:**

/// updateTInfosLocal works with services that fetch group information, such as searchTeamWithOption: and fetchTeamsWithTimestamp:completion: 
    /// option Query option: You can set the option to id(01) or name(10) or id|name(11); and set the search content
    NIMTeamSearchOption *option = [NIMTeamSearchOption new];
    /// Set the group ID for search
    [option setSearchContentOption:NIMTeamSearchContentOptiontId];
    /// Set the search content to @"6271272396"
    [option setSearchContent:@"6271272396"];
    /// completion Callback for completion
    NIMTeamSearchHandler completion = ^(NSError * __nullable error, NSArray<NIMTeam *> * __nullable teams)
    {
        if (error == nil) {
            /// Query success. The result includes a list of teams
            NSLog(@"[Search team with option %@ total %ld team(s) succeed.]", [option searchContent], [teams count]);
            ///=================================================
            /// teams List of groups to be updated
            NSArray<NIMTeam *> *updateTeams = teams;
            /// Update group local information
            BOOL didUpdate = [[[NIMSDK sharedSDK] teamManager] updateTInfosLocal:updateTeams];
            ///=================================================
            NSLog(@"[Update team info result: %@.]", didUpdate ? @"YES" : @"NO");
        } else {
            /// Query failed
            NSLog(@"[NSError message: %@]", error);
        }
        /// Query group information
        [[[NIMSDK sharedSDK] teamManager] searchTeamWithOption:option
                                                    completion:completion];
    };

Query group information

The NIM SDK will synchronize the local group information when the app starts. You can the local cache interface to get the group information.

The SDK allows users to get information about all groups you have joined, and query a specified group by group ID. The SDK also provides an interface for obtaining group information from the server.

Query information about all groups the current user has joined

Retrieve information about all groups from the server by calling the fetchTeamsWithTimestamp:completion: method and persists the data on the local storage.

Parameters:

Parameter Description
timestamp A value of 0 indicates that information about all groups are retrieved.
block Callback for completion

** Sample code:**

 /// timeInterval A value of 0 indicates that information about all groups are retrieved.
    NSTimeInterval timeInterval = 0;
    /// completion Callback for completion
    NIMTeamFetchTeamsHandler completion = ^(NSError * __nullable error, NSArray<NIMTeam *> * __nullable teams)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch %lu teams with timestamp.]", [teams count]);
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Retrieve information about all groups
    [[[NIMSDK sharedSDK] teamManager] fetchTeamsWithTimestamp:timeInterval
                                                   completion:completion];

Query all groups the current user has joined in the local database.

Query all groups the current user has joined in the local database by calling the allMyTeams method.

Sample code:

/// teams All groups the current user has joined
    NSArray<NIMTeam*> *teams = [[[NIMSDK sharedSDK] teamManager] allMyTeams];

Query a specified group by group ID

Query a specified group by calling the teamById method.

Call this method on the main thread. Otherwise, the app may crash or data may lose during read and write operations.

Sample code:

/// teamId Group ID
    NSString *teamId = @"6121310012";
    /// team contains specific group information for the group ID. If you are not in the group, this interface returns nil
    NIMTeam *team = [[[NIMSDK sharedSDK] teamManager] teamById:teamId];

** Local storage of group information in the SDK:**

When dismissing a group, leaving the group or being removed from the group, the local database will continue to retain the group information. If the user manually clears all local data, the server will not synchronize the invalid group data during the next login synchronization, and the information about the group the user has left will not be obtained.

Query a specified group from the server

/// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamFetchInfoHandler completion = ^(NSError * __nullable error, NIMTeam * __nullable team)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch teamId:%@’s infomation: %@ succeed.]", teamId, [team teamName]);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Get the data of a group member
    [[[NIMSDK sharedSDK] teamManager] fetchTeamInfo:teamId
                                         completion:completion];

If you have joined the queried group, the locally cached group data will be updated.

/// Array of group IDs
    NSArray<NSString *> *teamsId = [NSArray arrayWithObjects:@"6271272396", nil];
    /// completion Callback for completion
    NIMTeamFetchTeamInfoListHandler completion = ^(NSError * __nullable error,
                                                   NSArray<NIMTeam *> * __nullable teams,
                                                   NSArray<NSString *> * __nullable failedTeamIds)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch %lu teams succeeded, %lu failed in total.]", [teams count], [failedTeamIds count]);
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Get the information about multiple groups
    [[[NIMSDK sharedSDK] teamManager] fetchTeamInfoList:teamsId
                                             completion:completion];
  • If more than 10 elements exist in the array, the first 10 elements will be taken.
  • The group information retrieved from the server are not persisted locally.

Search groups with keywords by calling the searchTeamWithOption:completion: method.

NIMTeamSearchOption representation:

Parameter Description
searchContentOption The matching option is NIMTeamSearchContentOption
ignoreingCase Whether to ignore the casing, YES by default.
searchContent Keyword for search.

NIMTeamSearchContentOption enumeration:

typedef NS_OPTIONS(NSInteger, NIMTeamSearchContentOption ) {
   // Search group names
   NIMTeamSearchContentOptiontName = 1 < < 0,
   // Search group IDs
   NIMTeamSearchContentOptiontId = 1 < < 1,
   // Search group names and IDs
   NIMTeamSearchContentOptionTeamAll = NIMTeamSearchContentOptiontName | NIMTeamSearchContentOptiontId,
};

Sample code:

/// option Query option: You can set the option to id(01) or name(10) or id|name(11); and set the search content
    NIMTeamSearchOption *option = [NIMTeamSearchOption new];
    /// Set the group ID for search
    [option setSearchContentOption:NIMTeamSearchContentOptiontId];
    /// Set the search content to @"6271272396"
    [option setSearchContent:@"6271272396"];
    /// completion Callback for completion
    NIMTeamSearchHandler completion = ^(NSError * __nullable error, NSArray<NIMTeam *> * __nullable teams)
    {
        if (error == nil) {
            /// Query success. The result includes a list of teams
            NSLog(@"[Search team with option %@ total %ld team(s) succeed.]", [option searchContent], [teams count]);
            /// your code ...
        } else {
            /// Query failed
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Query group information
    [[[NIMSDK sharedSDK] teamManager] searchTeamWithOption:option
                                                completion:completion];

API reference

API
Description
addDelegate: Add listeners for group events.
removeDelegate: Remove listeners for group events
createTeam Create a group.
addUsers Invite to join a group.
acceptInviteWithTeam Accept an invitation to join a group.
rejectInviteWithTeam Reject an invitation to join a group.
applyToTeam Request to join a group
passApplyToTeam Approve the request to join a group.
rejectApplyToTeam Reject a request to join a group.
kickUsers Remove a member from a group.
quitTeam Leave a group.
transferManagerWithTeam Transfer the ownership of a group.
dismissTeam Dismiss a group.
updateTeamName Edit the name of a group.
updateTeamAvatar Edit the avatar of a group.
updateTeamIntro Edit the introduction of a group.
updateTeamAnnouncement Edit the announcement of a group.
updateTeamJoinMode Change the verification method.
updateTeamBeInviteMode Change the acceptance method for invitations.
updateTeamInviteMode Change the invite permission
updateTeamUpdateInfoMode Change the permission for editing group information.
updateTeamUpdateClientCustomMode Change the permission for editing the custom information about a group.
updateTeamCustomInfo Edit the custom information about a group.
updateTeamInfos Edit multiple fields of a group profile.
updateTInfosLocal Edit the local group profile
fetchTeamsWithTimestamp Retreive information about multiple groups from the server.
allMyTeams Query all groups the current user has joined in the local database.
teamById Query a specified group by group ID in the local database.
fetchTeamInfo Query a specified group from the server.
fetchTeamInfoList Query specified groups from the server
searchTeamWithOption Search groups with keywords.
Was this page helpful?
Yes
No
  • Listeners for group events
  • Workflow
  • Create a group
  • Join a group
  • Invite users to join a group
  • Request to join a group
  • Transfer the ownership of a group
  • Leave a group
  • Remove a member from a group
  • Leave a group
  • Dismiss a group
  • Edit the group profile
  • Edit the field of a group profile
  • Edit multiple fields of a group profile
  • Edit the local group profile
  • Query group information
  • Query information about all groups the current user has joined
  • Query all groups the current user has joined in the local database.
  • Query a specified group by group ID
  • Query a specified group from the server
  • Group search
  • API reference