// 创建一条消息V2TIMMessage msg = V2TIMManager.getMessageManager().createTextMessage("本地插入一条 C2C 消息");// 插入到本地存储V2TIMManager.getMessageManager().insertC2CMessageToLocalStorage(msg, "receiver_userID", "sender_userID", new V2TIMValueCallback<V2TIMMessage>() {@Overridepublic void onSuccess(V2TIMMessage message) {// 插入 C2C 消息成功}@Overridepublic void onError(int code, String desc) {// 插入 C2C 消息失败}});
// 创建一条消息V2TIMMessage *msg = [[V2TIMManager sharedInstance] createTextMessage:@"本地插入一条 C2C 消息"];// 插入到本地存储[[V2TIMManager sharedInstance] insertC2CMessageToLocalStorage:msgto:@"receiver_userID" // 接收者的 userIDsender:@"sender_userID" // 发送者的 userIDsucc:^{NSLog(@"插入 C2C 消息成功");} fail:^(int code, NSString *msg) {NSLog(@"插入 C2C 消息失败, code: %d, msg: %@", code, 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_;};V2TIMMessage message =V2TIMManager::GetInstance()->GetMessageManager()->CreateTextMessage(u8"本地插入一条 C2C 消息");V2TIMString userID = "receiver_userID";V2TIMString sender = "sender_userID";auto callback = new ValueCallback<V2TIMMessage>{};callback->SetCallback([=](const V2TIMMessage& message) {// 插入 C2C 消息成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 插入 C2C 消息失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->InsertGroupMessageToLocalStorage(message, userID, sender,callback);
// 创建一条消息V2TIMMessage msg = V2TIMManager.getMessageManager().createTextMessage("本地插入一条群消息");// 插入到本地存储V2TIMManager.getMessageManager().insertGroupMessageToLocalStorage(msg, "groupID", "sender_userID", new V2TIMValueCallback<V2TIMMessage>() {@Overridepublic void onSuccess(V2TIMMessage message) {// 插入群消息成功}@Overridepublic void onError(int code, String desc) {// 插入群消息失败}});
// 创建一条消息V2TIMMessage *msg = [[V2TIMManager sharedInstance] createTextMessage:@"本地插入一条群消息"];// 插入到本地存储[[V2TIMManager sharedInstance] insertGroupMessageToLocalStorage:msgto:@"groupID" // 群聊 groupIDsender:@"sender_userID" // 发送者的 userIDsucc:^{NSLog(@"插入群消息成功");} fail:^(int code, NSString *msg) {NSLog(@"插入群消息失败, code: %d, msg: %@", code, 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_;};V2TIMMessage message =V2TIMManager::GetInstance()->GetMessageManager()->CreateTextMessage(u8"本地插入一条群消息");V2TIMString groupID = "groupID";V2TIMString sender = "sender_userID";auto callback = new ValueCallback<V2TIMMessage>{};callback->SetCallback([=](const V2TIMMessage& message) {// 插入群消息成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 插入群消息失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->InsertGroupMessageToLocalStorage(message, groupID, sender,callback);
本页内容是否解决了您的问题?