Group system notification configuration
,配置页面如下所示:V2TIMGroupListener groupListener = new V2TIMGroupListener() {// 群成员相关通知、群生命周期相关通知、加群申请相关通知、话题事件监听回调等,不一一列举@Overridepublic void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {// 有新成员加入群,该群所有的成员都能收到}@Overridevoid onMemberLeave(String groupID, V2TIMGroupMemberInfo member) {// 有成员离开群,该群所有的成员都能收到}@Overridepublic void onReceiveRESTCustomData(String groupID, byte[] customData) {// 服务器发送的自定义系统通知}};V2TIMManager.getInstance().addGroupListener(groupListener);
[[V2TIMManager sharedInstance] addGroupListener:self];// 群成员相关通知、群生命周期相关通知、加群申请相关通知、话题事件监听回调等,不一一列举- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {// 有新成员加入群,该群所有的成员都能收到}- (void)onMemberLeave:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member {// 有成员离开群,该群所有的成员都能收到}- (void)onReceiveRESTCustomData:(NSString *)groupID data:(NSData *)data {// 服务器发送的自定义系统通知}
class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;// 群成员相关通知、群生命周期相关通知、加群申请相关通知、话题事件监听回调等,不一一列举void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {// 有新成员加入群,该群所有的成员都能收到}void OnMemberLeave(const V2TIMString& groupID, const V2TIMGroupMemberInfo& member) override {// 有成员离开群,该群所有的成员都能收到}void OnReceiveRESTCustomData(const V2TIMString& groupID, const V2TIMBuffer& customData) override {// 服务器发送的自定义系统通知}};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
searchGroups
(Android / iOS & Mac / Windows) 搜索本地群组。
您可以设置搜索关键字 keywordList
,并指定搜索的范围,即是否搜索群组的 userID
、groupName
字段。V2TIMGroupSearchParam searchParam = new V2TIMGroupSearchParam();searchParam.setKeywordList(Arrays.asList("keyword1", "keyword2", "keyword3")); // 设置搜索关键字列表,最多支持5个。searchParam.setSearchGroupID(true); // 设置是否搜索群 IDsearchParam.setSearchGroupName(true); // 设置是否搜索群名称V2TIMManager.getGroupManager().searchGroups(searchParam, new V2TIMValueCallback<List<V2TIMGroupInfo>>() {@Overridepublic void onSuccess(List<V2TIMGroupInfo> groupInfoList) {// 搜索群资料成功}@Overridepublic void onError(int code, String desc) {// 搜索群资料失败}});
V2TIMGroupSearchParam *searchParam = [[V2TIMGroupSearchParam alloc] init];searchParam.keywordList = @[@"keyword1", @"keyword2", @"keyword3"];searchParam.isSearchGroupID = true;searchParam.isSearchGroupName = true;// 搜索群资料[[V2TIMManager sharedInstance] searchGroups:searchParam succ:^(NSArray<V2TIMGroupInfo *> *groupList) {// 搜索群资料成功} fail:^(int code, NSString *desc) {// 搜索群资料失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMGroupSearchParam searchParam;searchParam.keywordList = keywordList;searchParam.isSearchGroupID = true;searchParam.isSearchGroupName = true;auto callback = new ValueCallback<V2TIMGroupInfoVector>{};callback->SetCallback([=](const V2TIMGroupInfoVector& groupInfoList) {// 搜索群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 搜索群组失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SearchGroups(searchParam, callback);
createGroup
参数说明如下表所示:addGroupListener
添加了群组事件监听器,群创建成功后会回调 onGroupCreated
(Android / iOS & Mac / Windows) 接口。V2TIMManager.getInstance().createGroup(V2TIMManager.GROUP_TYPE_WORK, null, "groupA", new V2TIMValueCallback<String>() {@Overridepublic void onSuccess(String s) {// 创建群组成功}@Overridepublic void onError(int code, String desc) {// 创建群组失败}});// 监听群组创建通知V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onGroupCreated(String groupID) {// 群创建回调,groupID 为新创建群组的 ID}});
// 创建群组[[V2TIMManager sharedInstance] createGroup:GroupType_Work groupID:nil groupName:@"groupA" succ:^(NSString *groupID) {// 创建群组成功} fail:^(int code, NSString *desc) {// 创建群组失败}];// 监听群组创建通知[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onGroupCreated:(NSString *)groupID {// 群创建回调,groupID 为新创建群组的 ID}
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new ValueCallback<V2TIMString>{};callback->SetCallback([=](const V2TIMString& string) {// 创建群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 创建群组失败delete callback;});V2TIMManager::GetInstance()->CreateGroup("Work", {}, "groupA", callback);// 监听群组创建通知class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnGroupCreated(const V2TIMString& groupID) override {// 群创建回调,groupID 为新创建群组的 ID}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
createGroup
(Android / iOS & Mac / Windows) 实现。创建成功的回调中会抛出 groupID
。// 使用高级版 createGroup 创建一个工作群V2TIMGroupInfo v2TIMGroupInfo = new V2TIMGroupInfo();v2TIMGroupInfo.setGroupName("testWork");v2TIMGroupInfo.setGroupType("Work");v2TIMGroupInfo.setIntroduction("this is a test Work group");List<V2TIMCreateGroupMemberInfo> memberInfoList = new ArrayList<>();V2TIMCreateGroupMemberInfo memberA = new V2TIMCreateGroupMemberInfo();memberA.setUserID("vinson");V2TIMCreateGroupMemberInfo memberB = new V2TIMCreateGroupMemberInfo();memberB.setUserID("park");memberInfoList.add(memberA);memberInfoList.add(memberB);V2TIMManager.getGroupManager().createGroup(v2TIMGroupInfo, memberInfoList, new V2TIMValueCallback<String>() {@Overridepublic void onError(int code, String desc) {// 创建失败}@Overridepublic void onSuccess(String groupID) {// 创建成功}});
// 使用高级版 createGroup 创建一个工作群V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];info.groupName = @"testWork";info.groupType = @"Work";NSMutableArray *memberList = [NSMutableArray array];V2TIMCreateGroupMemberInfo *memberInfo = [[V2TIMCreateGroupMemberInfo alloc] init];memberInfo.userID = @"vinson";[memberList addObject:memberInfo];[[V2TIMManager sharedInstance] createGroup:info memberList:memberList succ:^(NSString *groupID) {// 创建群组成功} fail:^(int code, NSString *msg) {// 创建群组失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};// 使用高级版 createGroup 创建一个工作群V2TIMGroupInfo info;info.groupType = "Work";info.groupName = "testWork";info.introduction = "this is a test Work group";V2TIMCreateGroupMemberInfoVector memberInfoList;V2TIMCreateGroupMemberInfo memberInfo1;memberInfo1.userID = "vinson";memberInfoList.PushBack(memberInfo1);V2TIMCreateGroupMemberInfo memberInfo2;memberInfo2.userID = "park";memberInfoList.PushBack(memberInfo2);auto callback = new ValueCallback<V2TIMString>{};callback->SetCallback([=](const V2TIMString& string) {// 创建成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 创建失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->CreateGroup(info, memberInfoList, callback);
类型 | 加群方法 |
好友工作群(Work) | 必须由其他群成员邀请 |
陌生人社交群(Public) | 用户申请,群主或管理员审批 |
临时会议群(Meeting) | 用户可随意加入 |
社群(Community) | 用户可随意加入 |
直播群(AVChatRoom) | 用户可随意加入 |
// 加入群组V2TIMManager.getInstance().joinGroup("groupA", "it's me!", new V2TIMCallback() {@Overridepublic void onSuccess() {// 加入群组成功}@Overridepublic void onError(int code, String desc) {// 加入群组失败}});// 监听加入群组事件V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {// 有人加入群组}});
// 加入群组[[V2TIMManager sharedInstance] joinGroup:@"groupA" msg:@"it's me!" succ:^{// 加入群组成功} fail:^(int code, NSString *desc) {// 加入群组失败}];// 监听加入群组事件[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {// 有人加入群组}
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new Callback{};callback->SetCallback([=]() {// 加入群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 加入群组失败delete callback;});V2TIMManager::GetInstance()->JoinGroup("groupA", "it's me!", callback);// 监听加入群组事件class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {// 有人加入群组}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
setGroupInfo
(Android / iOS & Mac / Windows)修改 V2TIMGroupInfo
的 groupApproveOpt
字段来打开邀请加群。// 邀请 userA 用户进入群组 groupA 中List<String> userIDList = new ArrayList<>();userIDList.add("userA");V2TIMManager.getGroupManager().inviteUserToGroup("groupA", userIDList, new V2TIMValueCallback<List<V2TIMGroupMemberOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMGroupMemberOperationResult> v2TIMGroupMemberOperationResults) {// 邀请进群成功}@Overridepublic void onError(int code, String desc) {// 邀请进群失败}});// 监听群组邀请事件V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onMemberInvited(String groupID, V2TIMGroupMemberInfo opUser, List<V2TIMGroupMemberInfo> memberList) {// 邀请进群事件。可以在这个回调中做一些 UI 上的提示}});
// 邀请 userA 用户进入群组 groupA 中[[V2TIMManager sharedInstance] inviteUserToGroup:@"groupA" userList:@[@"userA"] succ:^(NSArray<V2TIMGroupMemberOperationResult *> *resultList) {// 邀请进群成功} fail:^(int code, NSString *desc) {// 邀请进群失败}];// 监听群组邀请事件[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onMemberInvited:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {// 可以在这个回调中做一些 UI 上的提示}
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};// 邀请 userA 用户进入群组 groupA 中V2TIMStringVector userList;userList.PushBack("userA");auto callback = new ValueCallback<V2TIMGroupMemberOperationResultVector>{};callback->SetCallback([=](const V2TIMGroupMemberOperationResultVector& groupMemberOperationResultList) {// 邀请进群成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 邀请进群失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->InviteUserToGroup("groupA", userList, callback);// 监听群组邀请事件class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnMemberInvited(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser,const V2TIMGroupMemberInfoVector& memberList) override {// 邀请进群事件。可以在这个回调中做一些 UI 上的提示}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
onReceiveJoinApplication
(Android / iOS & Mac / Windows) ,在其中调用 getGroupApplicationList
(Android / iOS & Mac / Windows) 获取加群申请列表。acceptGroupApplication
(Android / iOS & Mac / Windows) 同意加群,或调用 refuseGroupApplication
(Android / iOS & Mac / Windows) 拒绝加群请求。onApplicationProcessed
(Android / iOS & Mac / Windows) 回调。其中 isAgreeJoin
为 true
/YES
表示同意加群,反之被拒绝。// ******群主端******//// 1、群主端修改加群选项为需要审核V2TIMGroupInfo groupInfo = new V2TIMGroupInfo();groupInfo.setGroupID("groupB");groupInfo.setGroupAddOpt(V2TIMGroupInfo.V2TIM_GROUP_ADD_AUTH);V2TIMManager.getGroupManager().setGroupInfo(groupInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// 修改加群选项成功}@Overridepublic void onError(int code, String desc) {// 修改加群选项失败}});// 2、群主端监听加群请求并处理V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onReceiveJoinApplication(String groupID, V2TIMGroupMemberInfo member, String opReason) {V2TIMManager.getGroupManager().getGroupApplicationList(new V2TIMValueCallback<V2TIMGroupApplicationResult>() {@Overridepublic void onSuccess(V2TIMGroupApplicationResult v2TIMGroupApplicationResult) {List<V2TIMGroupApplication> groupApplicationList = v2TIMGroupApplicationResult.getGroupApplicationList();for (V2TIMGroupApplication application : groupApplicationList) {if (application.getGroupID().equals(groupID) && application.getFromUser().equals(member.getUserID())) {// 同意进群if (agree) {// 同意入群申请V2TIMManager.getGroupManager().acceptGroupApplication(application, "agree", new V2TIMCallback() {@Overridepublic void onSuccess() {// 同意入群申请成功}@Overridepublic void onError(int code, String desc) {// 同意入群申请失败}});} else {// 拒绝入群申请V2TIMManager.getGroupManager().refuseGroupApplication(application, "not agree", new V2TIMCallback() {@Overridepublic void onSuccess() {// 拒绝入群申请成功}@Overridepublic void onError(int code, String desc) {// 拒绝入群申请失败}});}return;}}V2TIMManager.getGroupManager().setGroupApplicationRead(new V2TIMCallback() {@Overridepublic void onSuccess() {// 标记加群申请列表为已读成功}@Overridepublic void onError(int code, String desc) {// 标记加群申请列表为已读失败}});}@Overridepublic void onError(int code, String desc) {// 获取群申请列表失败}});}});// ******用户端******//// 1、用户端申请加群V2TIMManager.getInstance().joinGroup("groupB", "it's me!", new V2TIMCallback() {@Overridepublic void onSuccess() {// 加入群组成功}@Overridepublic void onError(int code, String desc) {// 加入群组失败}});// 2、用户端监听加群审批结果V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onApplicationProcessed(String groupID, V2TIMGroupMemberInfo opUser, boolean isAgreeJoin,String opReason) {// 请求加群申请被处理}@Overridepublic void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {// 如果加群申请通过,收到该回调}});
// ******群主端******//// 1、群主端修改加群选项为需要审核V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];info.groupID = @"groupA";info.groupAddOpt = V2TIM_GROUP_ADD_AUTH;[[V2TIMManager sharedInstance] setGroupInfo:info succ:^{// 修改加群选项成功} fail:^(int code, NSString *desc) {// 修改加群选项成功}];// 2、群主端监听加群请求并处理[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onReceiveJoinApplication:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member opReason:(NSString *)opReason {[[V2TIMManager sharedInstance] getGroupApplicationList:^(V2TIMGroupApplicationResult *result) {for (V2TIMGroupApplication *application in result.applicationList) {if ([application.groupID isEqualToString:groupID] && [application.fromUser isEqualToString:member.userID]) {// 同意进群[[V2TIMManager sharedInstance] acceptGroupApplication:application reason:@"agree" succ:^{// 同意入群申请成功} fail:^(int code, NSString *desc) {// 同意入群申请失败}];// 拒绝进群[[V2TIMManager sharedInstance] refuseGroupApplication:application reason:@"refuse" succ:^{// 拒绝入群申请成功} fail:^(int code, NSString *desc) {// 拒绝入群申请失败}];// 标记申请已读[[V2TIMManager sharedInstance] setGroupApplicationRead:^{// 标记加群申请列表为已读成功} fail:^(int code, NSString *desc) {// 标记加群申请列表为已读失败}];}}} fail:^(int code, NSString *desc) {// 获取群申请列表失败}];}// ******申请端******//// 1、用户端申请加群[[V2TIMManager sharedInstance] joinGroup:@"groupA" msg:@"it's me!" succ:^{// 加入群组成功} fail:^(int code, NSString *desc) {// 加入群组失败}];// 2、用户端监听加群审批结果[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onApplicationProcessed:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser opResult:(BOOL)isAgreeJoin opReason:(NSString *)opReason {// 请求加群申请被处理}- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList; {// 如果加群申请通过,收到该回调}
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};////////////////////////////////////////////////// 群主端 //////////////////////////////////////////////////// 1、群主端修改加群选项为需要审核V2TIMGroupInfo info;info.groupID = "groupB";info.groupAddOpt = V2TIMGroupAddOpt::V2TIM_GROUP_ADD_AUTH;info.modifyFlag = V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_GROUP_ADD_OPTION;auto callback = new Callback;callback->SetCallback([=]() {// 修改加群选项成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 修改加群选项失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupInfo(info, callback);// 2、群主端监听加群请求并处理class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnReceiveJoinApplication(const V2TIMString& groupID, const V2TIMGroupMemberInfo& member,const V2TIMString& opReason) override {auto callback = new ValueCallback<V2TIMGroupApplicationResult>{};callback->SetCallback([=](const V2TIMGroupApplicationResult& groupApplicationResult) {const V2TIMGroupApplicationVector& groupApplicationList =groupApplicationResult.applicationList;for (size_t i = 0; i < groupApplicationList.Size(); ++i) {const V2TIMGroupApplication& application = groupApplicationList[i];if (application.groupID == groupID && application.fromUser == member.userID) {if (...) { // 同意入群auto callback = new Callback;callback->SetCallback([=]() {// 同意入群申请成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 同意入群申请失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->AcceptGroupApplication(application, "agree", callback);} else { // 拒绝入群auto callback = new Callback;callback->SetCallback([=]() {// 拒绝入群申请成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 拒绝入群申请失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->RefuseGroupApplication(application, "refuse", callback);}break;}}auto callback = new Callback;callback->SetCallback([=]() {// 标记加群申请列表为已读成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 标记加群申请列表为已读失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupApplicationRead(callback);delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取群申请列表失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupApplicationList(callback);}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);////////////////////////////////////////////////// 用户端 //////////////////////////////////////////////////// 1、用户端申请加群auto callback = new Callback{};callback->SetCallback([=]() {// 加入群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 加入群组失败delete callback;});V2TIMManager::GetInstance()->JoinGroup("groupB", "it's me!", callback);// 2、用户端监听加群审批结果class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnApplicationProcessed(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser,bool isAgreeJoin, const V2TIMString& opReason) override {// 请求加群申请被处理}void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {// 如果加群申请通过,收到该回调}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
setGroupInfo
(Android / iOS & Mac / Windows) 接口调整加群选项(groupAddOpt
)和邀请加群审批选项(groupApproveOpt
),可以设置为更严格的 “禁止任何人加群”,也可以设置为更宽松的 “放开审批流程”。V2TIMGroupAddOpt
的可选项有:加群选项 | 含义 |
V2TIM_GROUP_ADD_FORBID | 禁止任何人加群。 |
V2TIM_GROUP_ADD_AUTH | 需要群主或管理员审批才能加入(默认值)。 |
V2TIM_GROUP_ADD_ANY | 取消审批流程,任何用户都可以加入。 |
V2TIMManager.getGroupManager().getJoinedGroupList(new V2TIMValueCallback<List<V2TIMGroupInfo>>() {@Overridepublic void onSuccess(List<V2TIMGroupInfo> v2TIMGroupInfos) {// 获取已加入的群组列表成功}@Overridepublic void onError(int code, String desc) {// 获取已加入的群组列表失败}});
[[V2TIMManager sharedInstance] getJoinedGroupList:^(NSArray<V2TIMGroupInfo *> *groupList) {// 获取已加入的群组列表成功} fail:^(int code, NSString *desc) {// 获取已加入的群组列表失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new ValueCallback<V2TIMGroupInfoVector>{};callback->SetCallback([=](const V2TIMGroupInfoVector& groupInfoList) {// 获取已加入的群组列表成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取已加入的群组列表失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetJoinedGroupList(callback);
quitGroup
(Android / iOS & Mac / Windows) 退出群组。
退群者会收到 onQuitFromGroup
(Android / iOS & Mac / Windows) 回调。
群组内其他成员会收到 onMemberLeave
(Android / iOS & Mac / Windows) 回调。V2TIMManager.getInstance().quitGroup("groupA", new V2TIMCallback() {@Overridepublic void onSuccess() {// 退出群组成功}@Overridepublic void onError(int code, String desc) {// 退出群组失败}});V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onMemberLeave(String groupID, V2TIMGroupMemberInfo member) {// 群成员离开回调}});
[[V2TIMManager sharedInstance] quitGroup:@"groupA" succ:^{// 退出群组成功} fail:^(int code, NSString *desc) {// 退出群组失败}];[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onMemberLeave:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member {// 群成员离开回调}
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new Callback{};callback->SetCallback([=]() {// 退出群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 退出群组失败delete callback;});V2TIMManager::GetInstance()->QuitGroup("groupA", callback);// 监听群成员离开通知class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnMemberLeave(const V2TIMString& groupID, const V2TIMGroupMemberInfo& member) override {// 群成员离开回调}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
dismissGroup
(Android / iOS & Mac / Windows) 解散群组,全员会收到 onGroupDismissed
(Android / iOS & Mac / Windows) 回调。V2TIMManager.getInstance().dismissGroup("groupA", new V2TIMCallback() {@Overridepublic void onSuccess() {// 解散群组成功}@Overridepublic void onError(int code, String desc) {// 解散群组失败}});V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onGroupDismissed(String groupID, V2TIMGroupMemberInfo opUser) {// 群被解散回调}@Overridepublic void onGroupRecycled(String groupID, V2TIMGroupMemberInfo opUser) {// 群被回收回调}});
[[V2TIMManager sharedInstance] dismissGroup:@"groupA" succ:^{// 解散群组成功} fail:^(int code, NSString *desc) {// 解散群组失败}];[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onGroupDismissed:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser {// 群被解散回调}- (void)onGroupRecycled:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser {// 群被回收回调}
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new Callback{};callback->SetCallback([=]() {// 解散群组成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 解散群组失败delete callback;});V2TIMManager::GetInstance()->DismissGroup("groupA", callback);// 监听群解散/回收通知class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnGroupDismissed(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser) override {// 群被解散回调}void OnGroupRecycled(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser) override {// 群被回收回调}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
onReceiveRESTCustomData
(Android / iOS & Mac / Windows) ,在其中抛出您发送的自定义数据。
本页内容是否解决了您的问题?