- Documentation
- In-app Chat
- Guides
- Group
- Manage groups
Manage groups
ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of group management, allowing you to create a group, ungroup, join and leave a group, and maintain the group relation chain.
With the group management feature, you can create different types of group chats as needed, such as colleague groups, social groups, fan groups, and more.
Prerequisites
- Create a project in ZEGOCLOUD Console. Then, contact Technical Support to activate the In-app Chat service, and get the AppID and ServerSecret for SDK integration. The ZIM service permission is not enabled by default. Before using it, please activate the ZIM service by yourself in ZEGOCLOUD Console (for details, please refer to Project Management - In-app Chat), if you cannot activate the ZIM service, please contact ZEGOCLOUD technical support to activate it.
- Get the Token that SDK required for login authentication. For details, see Authentication.
- Integrate the ZIM SDK. For details, see the Integrate the SDK chapter of Send and receive messages.
Create a group
Let's suppose we have Client A and other client users. The following shows how Client A creates the group, how other client users join and leave the room.
After Client A logs in, he can call the createGroup
method to create a new group, and he can be told whether the group is created successfully through the callback ZIMGroupCreatedCallback
. For related error codes, see Error codes.
Client A automatically becomes the group owner of the group. Other client users can join the group with a correct groupID.
- You can customize the
groupID
, and it can't start with "#", and it can only contain numbers, letters, and the following special characters: !#$%&()+-:;<=>.?@[]^_{}|~. We recommend you set thegroupID
to a meaningful value and associate them with the account system of your application. If you leave it empty, the ZIM Server automatically generates a groupID for you. - After creating a group by calling the
createGroup
method, you will directly join the group you just created, you don't need to call thejoinGroup
method to join the group again. - You will automatically become the group owner after you create a group successfully. To transfer the ownership, refer to chapter Transfer the group ownership of the Manage group members.
- After creating a group, for the group owner to send messages to a group, call the
sendGroupMessage
method. For details, see Send & Receive messages.
Sample method call
- (void)createGroup:(ZIMGroupInfo *)groupInfo
userIDs:(NSArray<NSString *> *)userIDs
config:(ZIMGroupAdvancedConfig *)config
callback:(ZIMGroupCreatedCallback)callback;
Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
groupInfo | ZIMGroupInfo |
Yes | Basic group info, such as groupID, group name. |
userIDs | NSArray<NSString *> * | Yes | Initial list of members selected when creating a group. UserIDs support a maximum of 100 users. That is, when creating a group, you can add 100 users to the group at the same time. |
config | ZIMGroupAdvancedConfig |
No | Advanced group properties. This parameter is required when creating a group with advanced group properties. |
callback | ZIMGroupCreatedCallback |
Yes | Callback for the results of create a group. |
Sample code
// Create a group.
[zim createGroup:myGroupID userIDs:userIDs callback:^(ZIMGroupFullInfo * _Nonnull groupInfo, NSArray<ZIMGroupMemberInfo *> * _Nonnull userList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
//Imeplement the event callback for creating a group here.
}];
Join a group
For a client user to join a group, choose either of the following methods:
Join a group directly (actively):
To join a group directly, call the
joinGroup
method with thegroupID
(an existing groupID). All group members including the client user himself receive a notification through the callbackgroupMemberStateChanged
after the client user joins the group successfully.
Join a group by invited by a group member (passively):
To invite a new member into the group, call the
inviteUsersIntoGroup
method with thegroupID
(an existing groupID), anduserIDList
(the ID of the user you want to invite). All group members including the client user himself receive a notification through the callbackgroupMemberStateChanged
after the client user joins the group successfully.
When an existing group member calls the inviteUsersIntoGroup
method to invite other users to the group:
- The invited client user will be directly joined to the group.
- The invited user must be an existing user (that is, the user must be logged in); otherwise, the operation fails.
- After joining a group, for the group members to send messages to a group, call the
sendGroupMessage
method. For details, see Send & Receive messages.
Join a group directly (actively)
Sample method call
- (void)joinGroup:(NSString *)groupID callback:(ZIMGroupJoinedCallback)callback;
Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
groupID | NSString | Yes | The ID of the group you will be joined to. |
callback | ZIMGroupJoinedCallback |
Yes | Callback for the results of joining a group. |
Join a group by being invited by a group member (passively)
Sample method call
- (void)inviteUsersIntoGroup:(NSArray<NSString *> *)userIDs groupID:(NSString *)groupID callback:(ZIMGroupUsersInvitedCallback)callback;
Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
userIDs | NSArray<NSString *> * | Yes | The user list that you want to invite to the current group. |
groupID | NSString | Yes | The ID of the group the invited user will be joined. |
callback | ZIMGroupUsersInvitedCallback |
Yes | Callback for the results of inviting a user to join the current group. |
Sample code
// Join a group directly.
[zim joinGroup:GroupID callback:^(ZIMGroupFullInfo * _Nonnull groupInfo, ZIMError * _Nonnull errorInfo) {
//Implement the event callback for joining a group here.
}];
// Join a group by being invited by a group member.
[zim inviteUsersIntoGroup:userIDs groupID:groupID callback:^(NSArray<ZIMGroupMemberInfo *> * _Nonnull userList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
//Implement the event callback for inviting a user to join to the current group here.
}];
Leave the group
For a client user to leave a group, choose either of the following methods:
Leave the group directly (actively):
To leave the group, call the
leaveGroup
method with thegroupID
(an existing groupID). All group members including the client user himself receive a notification through the callbackgroupMemberStateChanged
after the client user leaves the group successfully.
Leave the group by removed by the group owner (passively):
To remove a group member from the group, call the
kickGroupMembers
method with thegroupID
(an existing groupID), anduserIDList
(the ID of the user you want to remove). All group members including the client user himself receive a notification through the callbackgroupMemberStateChanged
after the client user was removed from the group successfully.
- Only the group owner can call the
kickGroupMembers
method to remove a group member from the group. And the group owner can remove a member when he is offline and without the member's consent. - The user to be removed must be in the member list of the group; otherwise, the operation fails.
- When the group owner leaves the group, the group owner will be automatically transferred to the earliest member who joined the group. When all members leave the group, the group is automatically dismissed.
Leave the group directly (actively)
Sample method call
- (void)leaveGroup:(NSString *)groupID callback:(ZIMGroupLeftCallback)callback;
Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
groupID | NSString | Yes | The ID of the group the user wants to leave. |
callback | ZIMGroupLeftCallback |
Yes | Callback for the results of leaving the group actively. |
Leave the group by removed by the group owner (passively)
Sample method call
- (void)kickGroupMembers:(NSArray<NSString *> *)userIDs groupID:(NSString *)groupID callback:(ZIMGroupMemberKickedCallback)callback;
Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
userIDs | NSArray<NSString *> * | Yes | The list of group members you want to remove. |
groupID | NSString | Yes | The ID of the group the user wants to leave. |
callback | ZIMGroupMemberKickedCallback |
Yes | Callback for the results of removing a group member. |
Sample code
// Leave the group directly (actively).
[zim leaveGroup:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for leaving the group actively here.
}];
// Leave the group by removed by the group owner (passively).
[zim kickGroupMembers:userIDs groupID:groupID callback:^(NSArray<NSString *> * _Nonnull kickedUserIDList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
//Implement the event callback of removing a group member here.
}];
Ungroup
For a group owner to ungroup, call the dismissGroup
method.
All group members receive a notification through the callback groupStateChanged
when ungroup operation succeeds.
- Only the group owner can call the
dismissGroup
to ungroup. - When all members leave the group, the group is automatically dismissed.
Sample method call
- (void)dismissGroup:(NSString *)groupID callback:(ZIMGroupDismissedCallback)callback;
- Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
groupID | NSString | Yes | The ID of the group you want to ungroup. |
callback | ZIMGroupDismissedCallback |
Yes | Callback for the results of ungroup. |
Sample code
// The group owner to ungroup.
[zim dismissGroup:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for ungroup here.
}];
Get the list of joined groups
To know what groups you have joined after login, call the queryGroupList
method.
Sample method call
- (void)queryGroupList:(ZIMGroupListQueriedCallback)callback;
- Parameter description
Parameter | Type | Required | Description |
---|---|---|---|
callback | ZIMGroupListQueriedCallback |
Yes | Callback for the results of querying the list of joined groups. |
Sample code
// Get the list of joined groups.
[zim queryGroupListByGroupID:^(NSArray<ZIMGroupInfo *> * _Nonnull groupList, ZIMError * _Nonnull errorInfo) {
//Implement the event callback for querying the list of joined groups.
}];