createCustomMessage
(Android / iOS & Mac / Windows) 接口创建一条用于投票的自定义消息,其中 data
存储投票的标题和选项,然后用消息扩展 key 存储投票用户 ID,用消息扩展 value 存储投票用户选项,有了每个用户的投票选项,我们就可以动态计算出投票选项的用户占比。createCustomMessage
接口创建一条用于接龙的自定义消息,其中 data
存储接龙的标题,然后用消息扩展 key 存储接龙用户 ID,用消息扩展 value 存储接龙信息。createCustomMessage
接口创建一条用于问卷调查的自定义消息,其中 data
存储问卷调查的标题和选项,然后用消息扩展 key 存储问卷调查的用户 ID,用消息扩展 value 存储问卷调查信息。setMessageExtensions
(Android / iOS & Mac / Windows) 接口可以设置消息扩展,如果扩展 key 已经存在,则修改扩展的 value 信息,如果扩展 key 不存在,则新增扩展。List<V2TIMMessageExtension> extensionList = new ArrayList<>();V2TIMMessageExtension extension1 = new V2TIMMessageExtension();extension1.setExtensionKey("key1");extension1.setExtensionValue("value1");extensionList.add(extension1);V2TIMMessageExtension extension2 = new V2TIMMessageExtension();extension2.setExtensionKey("key2");extension2.setExtensionValue("value2");extensionList.add(extension2);V2TIMManager.getMessageManager().setMessageExtensions(lastMsg, extensionList, new V2TIMValueCallback<List<V2TIMMessageExtensionResult>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtensionResult> v2TIMMessageExtensionResults) {// 设置消息扩展成功}@Overridepublic void onError(int code, String desc) {// 设置消息扩展失败}});
NSMutableArray *extensionList = [NSMutableArray array];V2TIMMessageExtension *extension1 = [[V2TIMMessageExtension alloc] init];extension1.extensionKey = @"key1";extension1.extensionValue = @"value1";[extensionList addObject:extension1];V2TIMMessageExtension *extension2 = [[V2TIMMessageExtension alloc] init];extension2.extensionKey = @"key2";extension2.extensionValue = @"value2";[extensionList addObject:extension2];[[V2TIMManager sharedInstance] setMessageExtensions:message extensions:extensionList succ:^(NSArray<V2TIMMessageExtensionResult *> *extensionResultList) {// 设置消息扩展成功} fail:^(int code, NSString *desc) {// 设置消息扩展失败}];
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_;};V2TIMMessageExtensionVector extensionList;V2TIMMessageExtension extension1;extension1.extensionKey = "key1";extension1.extensionValue = "value1";extensionList.PushBack(extension1);V2TIMMessageExtension extension2;extension2.extensionKey = "key2";extension2.extensionValue = "value2";extensionList.PushBack(extension2);auto *callback = new ValueCallback<V2TIMMessageExtensionResultVector>{};callback->SetCallback([=](const V2TIMMessageExtensionResultVector &extensionResultList) {// 设置消息扩展成功delete callback;},[=](int error_code, const V2TIMString &error_message) {// 设置消息扩展失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->SetMessageExtensions(message, extensionList, callback);
V2TIMManager.getMessageManager().getMessageExtensions(lastMsg, new V2TIMValueCallback<List<V2TIMMessageExtension>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtension> extensions) {// 获取消息扩展成功}@Overridepublic void onError(int code, String desc) {// 获取消息扩展失败}});
[[V2TIMManager sharedInstance] getMessageExtensions:message succ:^(NSArray<V2TIMMessageExtension *> *extensionList) {// 获取消息扩展成功} fail:^(int code, NSString *desc) {// 获取消息扩展失败}];
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<V2TIMMessageExtensionVector>{};callback->SetCallback([=](const V2TIMMessageExtensionVector &extensionList) {// 获取消息扩展成功delete callback;},[=](int error_code, const V2TIMString &error_message) {// 获取消息扩展失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->GetMessageExtensions(message, callback);
deleteMessageExtensions
(Android / iOS & Mac / Windows) 接口删除指定消息扩展,如果 keys
字段填 null
/nil
,则会清空所有消息扩展。List<String> keyList = new ArrayList<>();keyList.add("key1");keyList.add("key2");V2TIMManager.getMessageManager().deleteMessageExtensions(lastMsg, keyList, new V2TIMValueCallback<List<V2TIMMessageExtensionResult>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtensionResult> v2TIMMessageExtensionResults) {// 删除消息扩展成功}@Overridepublic void onError(int code, String desc) {// 删除消息扩展失败}});
[[V2TIMManager sharedInstance] deleteMessageExtensions:message keys:@[@"key1",@"key2"] succ:^(NSArray<V2TIMMessageExtensionResult *> *extensionResultList){// 删除消息扩展成功} fail:^(int code, NSString *desc) {// 删除消息扩展失败}];
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_;};V2TIMStringVector keys;keys.PushBack("key1");keys.PushBack("key2");auto *callback = new ValueCallback<V2TIMMessageExtensionResultVector>{};callback->SetCallback([=](const V2TIMMessageExtensionResultVector &extensionResultList) {// 删除消息扩展成功delete callback;},[=](int error_code, const V2TIMString &error_message) {// 删除消息扩展失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->DeleteMessageExtensions(message, keys, callback);
addAdvancedMsgListener
添加了高级消息事件监听器,当消息扩展发生了新增或者更新,您会收到 onRecvMessageExtensionsChanged
(Android / iOS & Mac / Windows) 回调,当消息扩展发生了删除,您会收到 onRecvMessageExtensionsDeleted
(Android / iOS & Mac / Windows) 回调。V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {@Overridepublic void onRecvMessageExtensionsChanged(String msgID, List<V2TIMMessageExtension> extensions) {// 收到消息扩展变更通知}@Overridepublic void onRecvMessageExtensionsDeleted(String msgID, List<String> extensionKeys) {// 收到消息扩展删除通知}});
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];- (void)onRecvMessageExtensionsChanged:(NSString *)msgID extensions:(NSArray<V2TIMMessageExtension *> *)extensions {// 收到消息扩展变更通知}- (void)onRecvMessageExtensionsDeleted:(NSString *)msgID extensionKeys:(NSArray<NSString *> *)extensionKeys {// 收到消息扩展删除通知}
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {public:void OnRecvMessageExtensionsChanged(const V2TIMString &msgID,const V2TIMMessageExtensionVector &extensions) override {// 收到消息扩展变更通知}void OnRecvMessageExtensionsDeleted(const V2TIMString &msgID,const V2TIMStringVector &extensionKeys) override {// 收到消息扩展删除通知}// 其他成员 ...};// 添加高级消息的事件监听器,注意在移除监听器之前需要保持 advancedMsgListener 的生命期,以免接收不到事件回调AdvancedMsgListener advancedMsgListener;V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
本页内容是否解决了您的问题?