V2TIMManager.getGroupManager().initGroupAttributes("groupA", attributeMap, new V2TIMCallback() {@Overridepublic void onSuccess() {// 初始化群属性成功}@Overridepublic void onError(int code, String desc) {// 初始化群属性失败}});
[[V2TIMManager sharedInstance] initGroupAttributes:@"groupA" attributes:@{@"key1" : @"value1"} succ:^{// 初始化群属性成功} fail:^(int code, NSString *desc) {// 初始化群属性失败}];
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_;};V2TIMString groupID = "groupA";V2TIMGroupAttributeMap attributes;attributes.Insert("key1", "value1");attributes.Insert("key2'", "value2");auto callback = new Callback;callback->SetCallback([=]() {// 初始化群属性成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 初始化群属性失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->InitGroupAttributes(groupID, attributes, callback);
HashMap<String, String> attributeMap = new HashMap<>();attributeMap.put("key1", "value1");attributeMap.put("key2", "value2");V2TIMManager.getGroupManager().setGroupAttributes("groupA", attributeMap, new V2TIMCallback() {@Overridepublic void onSuccess() {// 设置群属性成功}@Overridepublic void onError(int code, String desc) {// 设置群属性失败}});
[[V2TIMManager sharedInstance] setGroupAttributes:@"groupA" attributes:@{@"key1" : @"value1"} succ:^{// 设置群属性成功} fail:^(int code, NSString *desc) {// 设置群属性失败}];
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_;};V2TIMString groupID = "groupA";V2TIMGroupAttributeMap attributes;attributes.Insert("key1", "value1");attributes.Insert("key2'", "value2");auto callback = new Callback;callback->SetCallback([=]() {// 设置群属性成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 设置群属性失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupAttributes(groupID, attributes, callback);
deleteGroupAttributes
(Android / iOS & Mac / Windows) 接口可以删除指定群属性,如果 keys
字段填 null
/nil
,则会清空所有的群属性。List<String> keyList = new ArrayList<>();keyList.add("key1");V2TIMManager.getGroupManager().deleteGroupAttributes("groupA", keyList, new V2TIMCallback() {@Overridepublic void onSuccess() {// 删除成功}@Overridepublic void onError(int code, String desc) {// 删除失败}});
[[V2TIMManager sharedInstance] deleteGroupAttributes:@"groupA" keys:@[@"key1"] succ:^{// 删除成功} fail:^(int code, NSString *desc) {// 删除失败}];
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_;};V2TIMString groupID = "groupA";V2TIMStringVector keys;keys.PushBack("key1");keys.PushBack("key2");auto callback = new Callback;callback->SetCallback([=]() {// 删除群属性成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 删除群属性失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->DeleteGroupAttributes(groupID, keys, callback);
getGroupAttributes
接口 SDK 限制为单个登录用户 5 秒 20 次。V2TIMManager.getGroupManager().getGroupAttributes("groupA", null, new V2TIMValueCallback<Map<String, String>>() {@Overridepublic void onSuccess(Map<String, String> stringStringMap) {// 获取成功}@Overridepublic void onError(int code, String desc) {// 获取失败}});
[[V2TIMManager sharedInstance] getGroupAttributes:@"groupA" keys:nil succ:^(NSMutableDictionary<NSString *,NSString *> *groupAttributeList) {// 获取成功} 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<V2TIMGroupAttributeMap>{};callback->SetCallback([=](const V2TIMGroupAttributeMap& groupAttributeMap) {// 获取群属性成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取群属性失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupAttributes("groupID", {}, callback);
addGroupListener
添加了群组事件监听器,群属性有任何的更新变化,都会通过 onGroupAttributeChanged
(Android / iOS & Mac / Windows) 回调出来所有的群属性字段。V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onGroupAttributeChanged(String groupID, Map<String, String> groupAttributeMap) {// 群属性变更通知}});
[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onGroupAttributeChanged:(NSString *)groupID attributes:(NSMutableDictionary<NSString *,NSString *> *)attributes {// 群属性变更通知}
class GroupListener final : public V2TIMGroupListener {public:GroupListener() = default;~GroupListener() override = default;void OnGroupAttributeChanged(const V2TIMString& groupID,const V2TIMGroupAttributeMap& groupAttributeMap) override {// 群属性变更通知}// 其他成员 ...};// 添加群事件监听器,注意在移除监听器之前需要保持 groupListener 的生命期,以免接收不到事件回调GroupListener groupListener;V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
initGroupAttributes
、setGroupAttributes
、deleteGroupAttributes
接口合并计算,SDK 限制为单个登录用户 5 秒 10 次,超过后回调 8511 错误码;后台限制单个登录用户 1 秒 5 次,超过后返回 10049 错误码。getGroupAttributes
接口 SDK 限制为单个登录用户 5 秒 20 次。
本页内容是否解决了您的问题?