当前页

ZIM 升级指南

2026-07-24

本文介绍 ZIM Android 平台 SDK 版本升级时的一些说明和注意事项。

3.1.0 升级指南

注意

ZIM SDK 3.1.0 版本新增了部分接口废弃标记,请参考以下说明完成迁移。

新增废弃接口

queryGroupMessageReceiptReadMemberListqueryGroupMessageReceiptUnreadMemberList 自 3.1.0 版本起新增废弃标记,查询群消息的已读、未读(未送达)、或已送达状态的成员列表请使用 queryGroupMessageReceiptMemberList 代替。

queryGroupMessageReceiptMemberList 使用示例

参数说明:

参数说明
message需要查询的带回执的消息。
groupID对应群会话的群 ID。
count查询的人数,单次查询不超过 100。
config查询的配置项:ZIMGroupMessageReceiptMemberQueryConfig,可以配置查询起始标记 nextFlag 以及查询项(已读、未读[未送达]、已送达)。
callback查询结果的回调:ZIMGroupMessageReceiptMemberListQueriedCallback,其中 userList 为符合查询条件的群成员列表,nextFlag 为下一次查询的起始标记(当 nextFlag 为 0 时表示查询完毕)。

调用示例:

zim::ZIMGroupMessageReceiptMemberQueryConfig config;
config.nextFlag = 0;    // 查询的起始标记,初始填 0,后续填从 callback 里返回的 nextFlag。
config.count = 10;      // 需要查询的用户数量,单次不超过 100。

zim->queryGroupMessageReceiptMemberList(
    message, groupID, count, config,
    [=](const std::string &groupID, const std::vector<ZIMGroupMemberInfo> &userList,
        unsigned int nextFlag, const ZIMError &errorInfo) {
        if (errorInfo.code == 0) {
            // 查询成功,userList 为符合查询条件的群成员列表
            // nextFlag 为下一次查询的起始标记,nextFlag 为 0 时表示查询完毕
        } else {
            // 查询失败
        }
    });

3.0.0 升级指南

注意

本次版本(3.0.0)移除了部分已废弃超过 1 年的接口及相关枚举值和字段,同时对部分接口新增了废弃标记。请参考以下说明完成迁移。

废弃接口删除

ZIM 初始化接口(create)

废弃的旧版 create(appID, application) 接口已被移除,请使用接受 ZIMAppConfig 参数的 create 接口代替。

ZIMAppConfig appConfig;
appConfig.appID = 12345678;
appConfig.appSign = "appSign";
ZIM *zim = ZIM::create(appConfig);

ZIM 登录接口(login)

废弃的旧版 login(ZIMUserInfo, token, callback) 接口已被移除,请使用接受 userIDZIMLoginConfig 参数的 login 接口代替。

ZIMLoginConfig loginConfig;
loginConfig.userName = "userName";
loginConfig.token = ""; // 若使用 Token 鉴权,请填写 Token
loginConfig.isOfflineLogin = false;
zim->login("userID", loginConfig, [=](const ZIMError &errorInfo) {
    // 登录结果
});

ZIM 消息发送接口(sendMessage)

废弃的 sendPeerMessagesendRoomMessagesendGroupMessage 以及不含 ZIMMessageSendNotification 参数的旧版 sendMessage 接口已被移除,请统一使用带 notification 参数的 sendMessage 接口代替。

auto textMessage = std::make_shared<ZIMTextMessage>();
textMessage->message = "Hello";
ZIMMessageSendConfig config;
auto notification = std::make_shared<ZIMMessageSendNotification>();
notification->onMessageAttached = [=](const std::shared_ptr<ZIMMessage> &message) {
    // 消息发送前的业务逻辑
};
zim->sendMessage(textMessage, "toConversationID",
    ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER, config, notification,
    [=](const std::shared_ptr<ZIMMessage> &message, const ZIMError &errorInfo) {
        // 消息发送结果
    });

ZIM 媒体文件下载接口(downloadMediaFile)

废弃的旧版 downloadMediaFile(不含 config 参数)接口已被移除,请使用含 ZIMMediaDownloadConfig 参数的新版 downloadMediaFile 接口代替。

auto imageMessage = std::static_pointer_cast<ZIMImageMessage>(message);
ZIMMediaDownloadConfig config;
zim->downloadMediaFile(imageMessage,
    ZIMMediaFileType::ZIM_MEDIA_FILE_TYPE_ORIGINAL_FILE, config,
    [=](const std::shared_ptr<ZIMMessage> &msg,
        unsigned long long currentFileSize, unsigned long long totalFileSize) {
        // 下载进度
    },
    [=](const std::shared_ptr<ZIMMessage> &msg, const ZIMError &errorInfo) {
        // 下载完成
    });

ZIM 消息接收回调接口

在 2.18.0 中已废弃的 onReceivePeerMessageonReceiveRoomMessageonReceiveGroupMessage 回调在本版本中正式移除,建议迁移至 onMessageReceived

virtual void onMessageReceived(ZIM *zim,
        const ZIMMessageReceivedEventResult &result) override {
    auto &messageList = result.messageList;
    auto &info = result.info;
    auto &conversationID = result.conversationID;
    auto conversationType = result.conversationType;
    // 根据 conversationType 处理不同类型会话的消息
}

ZIM 呼叫邀请回调接口

旧版 onCallInvitationTimeout(zim, callID)onCallInvitationRejectedonCallInvitationAcceptedonCallInviteesAnsweredTimeout 回调已被移除,请使用新版 onCallInvitationTimeoutonCallUserStateChanged 代替。

virtual void onCallInvitationTimeout(ZIM *zim,
        const ZIMCallInvitationTimeoutInfo &info,
        const std::string &callID) override {
    // info.mode 可区分普通模式/进阶模式
}

virtual void onCallUserStateChanged(ZIM *zim,
        const ZIMCallUserStateChangeInfo &info,
        const std::string &callID) override {
    // info.callUserList 包含状态变更的用户列表
    // 可统一处理接受、拒绝、超时等状态变更
}

importLocalMessages / exportLocalMessages 接口删除

importLocalMessagesexportLocalMessages 接口已在 3.0.0 版本中暂时移除,且暂无替代接口。后续版本将重新开放该功能,请关注 SDK 更新日志。

新增废弃接口(建议迁移)

ZIM 消息接收回调接口

onPeerMessageReceivedonRoomMessageReceivedonGroupMessageReceived 回调在本版本中新增废弃标记,当前仍可正常使用,但建议尽快迁移至 onMessageReceived

virtual void onMessageReceived(ZIM *zim,
        const ZIMMessageReceivedEventResult &result) override {
    auto &messageList = result.messageList;
    auto &info = result.info;
    auto &conversationID = result.conversationID;
    auto conversationType = result.conversationType;
    // 根据 conversationType 处理不同类型会话的消息
}

ZIMGroupConversation 废弃

ZIMGroupConversation 类在 3.0.0 中已被废弃,其中的 isDisabledmutedExpiredTime 字段请通过基类 ZIMConversation 的对应属性替代:

ZIMGroupConversation(已废弃)ZIMConversation(替代属性)
isDisabledisConversationDisabled
mutedExpiredTimeselfMutedExpiredTime
bool isDisabled = conversation.isConversationDisabled;
long long mutedExpiredTime = conversation.selfMutedExpiredTime;

枚举值移除

ZIMMessageType 枚举值移除

SYSTEM(值为 30)已从 ZIMMessageType 枚举中移除,同时 ZIMSystemMessage 类也已被移除。如需发送系统级指令,请使用 ZIMCommandMessage 代替。

// 使用 ZIMCommandMessage 代替 ZIMSystemMessage
auto commandMessage = std::make_shared<ZIMCommandMessage>();
commandMessage->message = {/* payload bytes */};
zim->sendMessage(commandMessage, "toConversationID",
    ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER,
    ZIMMessageSendConfig{}, nullptr,
    [=](const std::shared_ptr<ZIMMessage> &msg, const ZIMError &errorInfo) {});

ZIMCallUserState 枚举值移除

OFFLINE(值为 4)已从 ZIMCallUserState 枚举中移除,请检查代码中是否有对该枚举值的判断并将其删除。

// 以下枚举值已移除,请检查并删除代码中对该值的引用
// ZIMCallUserState::ZIM_CALL_USER_STATE_OFFLINE  (值为 4)

字段变更

ZIMUserFullInfo.userAvatarUrl 废弃

ZIMUserFullInfo.userAvatarUrl 已废弃,请使用 ZIMUserFullInfo.baseInfo.userAvatarUrl 代替。

std::string avatarUrl = userFullInfo.baseInfo.userAvatarUrl;

ZIMMessage.conversationSeq 替换为 messageSeq

ZIMMessage.conversationSeq 已被移除,请使用 ZIMMessage.messageSeq 代替。

long long seq = message->messageSeq;

ZIMMessageDeletedInfo.isDeleteConversationAllMessage 移除

ZIMMessageDeletedInfo.isDeleteConversationAllMessage 已被移除,请使用 ZIMMessageDeletedInfo.messageDeleteType 代替。

ZIMMessageDeleteType deleteType = deletedInfo.messageDeleteType;
// 通过 deleteType 判断是单条删除还是全量删除

ZIMGroupMemberInfo.memberAvatarUrl 移除

ZIMGroupMemberInfo.memberAvatarUrl 已被移除,请使用 ZIMGroupMemberInfo.userAvatarUrl 代替。

std::string avatarUrl = groupMemberInfo.userAvatarUrl;

ZIMGroupOperatedInfo 结构变更

ZIMGroupOperatedInfo.operatedUserInfo 字段已被移除,其内部字段已平铺到 ZIMGroupOperatedInfo,可直接从 ZIMGroupOperatedInfo 中获取对应字段。

// 直接从 ZIMGroupOperatedInfo 获取字段
std::string operatorUserID = groupOperatedInfo.userID;
std::string operatorUserName = groupOperatedInfo.userName;
std::string operatorAvatarUrl = groupOperatedInfo.userAvatarUrl;

ZIMCallInvitationSentInfo.errorInvitees 替换

ZIMCallInvitationSentInfo.errorInvitees 已被移除,请使用 ZIMCallInvitationSentInfo.errorUserList 代替,类型由 List<ZIMCallUserInfo> 变更为 List<ZIMErrorUserInfo>

zim->callInvite(invitees, config,
    [=](const std::string &callID,
        const ZIMCallInvitationSentInfo &info,
        const ZIMError &errorInfo) {
        for (const auto &errorUser : info.errorUserList) {
            // errorUser.userID, errorUser.reason
        }
    });

ZIMConversationChangeInfo 字段变更

ZIMConversationChangeInfo 中的 event 属性(类型 ZIMConversationEvent)已被移除,请使用同结构下的 action 属性(类型 ZIMConversationChangeAction)代替。

virtual void onConversationChanged(ZIM *zim,
        const ZIMConversationChangeEventResult &result) override {
    for (const auto &changeInfo : result.infoList) {
        ZIMConversationChangeAction action = changeInfo.action;
        // 根据 action 处理会话变更
    }
}

接口命名与签名变更

以下变更在 3.0.0 中可能导致编译错误,请根据提示完成相应修改。

ZIMMessage getter 方法重命名

ZIMMessage 中以下 getter 方法已重命名,升级后需要同步修改调用方式:

旧方法名新方法名
isUserInserted()getIsUserInserted()
isBroadcastMessage()getIsBroadcastMessage()
isServerMessage()getIsServerMessage()
isMentionAll()getIsMentionAll()
isGroupTargetedMessage()getIsGroupTargetedMessage()
bool isUserInserted = message->getIsUserInserted();
bool isBroadcastMessage = message->getIsBroadcastMessage();
bool isServerMessage = message->getIsServerMessage();
bool isMentionAll = message->getIsMentionAll();
bool isGroupTargetedMessage = message->getIsGroupTargetedMessage();

回调接口方法重命名

类序列化方式变更

回调签名变更

以下事件回调的参数签名有变化,需要同步修改实现代码:

onBlacklistChangedaction 参数移除 const &

virtual void onBlacklistChanged(ZIM *zim,
        const std::vector<ZIMUserInfo> &userList,
        ZIMBlacklistChangeAction action) override {}

onFriendListChangedaction 参数移除 &

virtual void onFriendListChanged(ZIM *zim,
        const std::vector<ZIMFriendInfo> &friendInfoList,
        ZIMFriendListChangeAction action) override {}

onFriendApplicationListChangedaction 参数移除 &

virtual void onFriendApplicationListChanged(ZIM *zim,
        const std::vector<ZIMFriendApplicationInfo> &applicationList,
        ZIMFriendApplicationListChangeAction action) override {}

onRoomMemberAttributesUpdatedoperatedInfo 参数增加 const &

virtual void onRoomMemberAttributesUpdated(ZIM *zim,
        const std::vector<ZIMRoomMemberAttributesUpdateInfo> &infos,
        const ZIMRoomOperatedInfo &operatedInfo,
        const std::string &roomID) override {}

ZIMMessageRevokeConfig 字段重命名

ZIMMessageRevokeConfig 中的 config 字段已重命名为 pushConfig,请检查并替换所有相关引用。

ZIMMessageRevokeConfig revokeConfig;
ZIMPushConfig pushConfig;
pushConfig.title = "通知标题";
revokeConfig.pushConfig = pushConfig;

ZIMCombineMessageDetailQueriedCallback 参数变更

ZIMCombineMessageDetailQueriedCallback 回调的参数签名有以下变化:

  • message 参数:由 const std::shared_ptr<ZIMCombineMessage> & 变更为 std::shared_ptr<ZIMCombineMessage>(移除 const &
  • error 参数:由 ZIMError & 变更为 const ZIMError &(增加 const
zim->queryCombineMessageDetail(combineMessage,
    [=](std::shared_ptr<ZIMCombineMessage> message, const ZIMError &errorInfo) {
        // 处理结果
    });

ZIMMessage.rootRepliedCount 类型变更

ZIMMessagerootRepliedCount 字段类型由 int 变更为 unsigned int,请检查代码中涉及该字段赋值或与有符号整数比较的逻辑,避免类型转换问题。

unsigned int count = message->rootRepliedCount;

其他方法重命名

ZIMTipsMessagePinStatusChangeInfoisPinned() 重命名为 getIsPinned()

bool isPinned = pinStatusChangeInfo->getIsPinned();

ZIMImageMessage — 缩略图尺寸获取方法重命名:

int width = imageMessage->getThumbnailWidth();
int height = imageMessage->getThumbnailHeight();

枚举值重命名

以下枚举值在 3.0.0 中发生重命名,升级后请检查并替换代码中所有相关引用。

ZIMCallUserState

ZIMMediaFileType

ZIMGroupMessageNotificationStatus

setRoomMembersAttributes 行为变更

从 3.0.0 版本开始,如果通过 setRoomMembersAttributes 设置房间用户属性时,isDeleteAfterOwnerLeftfalse,那么房间用户属性不会在用户离开房间后删除。在 2.x.x 版本中,用户离开房间后会先删除属性,用户回到房间后会再次恢复。


2.28.0 升级指南

注意

ZIM SDK 2.28.0 版本调整了部分接口的返回参数和事件回调触发的时机。从旧版本升级到 2.28.0 版本时,请您阅读以下指南。

接口返回参数变更

ZIMMessageReactionUserListQueriedCallback 回调,将返回的用户表态详情列表类型从 ZIMMessageReactionUserInfo 改为 ZIMMessageReactionUserFullInfo,可用于更加详细的业务 UI 展示。

zim->queryMessageReactionUserList(message, config, 
        [=](const std::shared_ptr<ZIMMessage> &message,
// !mark
            const std::vector<ZIMMessageReactionUserFullInfo> &userInfoList,
            const std::string &reactionType, const long long nextFlag,
            const unsigned int totalCount, const ZIMError &errorInfo) {
        // Do business logic
});

事件回调时机变更

注意

以下回调自 2.28.0 版本起触发时机有变化,建议开发者检查相应业务逻辑在升级 SDK 后是否受到影响。

1

onMessageReactionsChanged

2

onConversationChanged

onConversationChanged 回调会在客户端端调用 deleteConversation 成功后触发。

3

onConversationsAllDeleted

onConversationsAllDeleted 回调会在客户端端调用 deleteAllConversations 成功后触发。

2.27.0 升级指南

注意

从 2.27.0 版本开始,以下接口有重大变更,因此在从旧版本升级到 2.27.0 版本时,请您阅读以下指南。

queryGroupList 及相关回调

原接口 queryGroupList,新增一个重载接口 queryGroupList 代替。新版本的 queryGroupList 新增了 countconfig 参数,可用于查询共同加入的群组列表。

ZIMGroupListQueriedCallback 回调,新增了 nextFlag 参数,可用于分页查询锚点。

zim_->queryGroupList(
    [=](const std::vector<ZIMGroupInfo> &groupList, long long nextFlag, zim::ZIMError errorInfo){
        int error_code = errorInfo.code;
    });

2.19.0 升级指南

注意

从 2.19.0 版本开始,以下接口有重大变更,因此在从旧版本升级到 2.19.0 版本时,请您阅读以下指南。

downloadMediaFile 及相关回调

废弃原接口 downloadMediaFile,请使用同名 downloadMediaFile 代替。新版本的 downloadMediaFile 新增了 config 参数,新增了 config 参数,可用于指定下载组合消息中的单个媒体内容。

ZIMMediaDownloadingProgress 以及 ZIMMediaDownloadedCallback 中,参数 message 的类型从 const std::shared_ptr<ZIMMediaMessage> & 变更为 const std::shared_ptr<ZIMMessage> &,以适应组合消息使用,开发者需要根据 IDE 的编译错误提示修正调用。

// 假设 multipleMessage.messageInfoList[0] 是文本消息,multipleMessage.messageInfoList[1] 是图片消息
auto multipleMessage = std::static_pointer_cast<ZIMMultipleMessage>(message);
// !mark(1:3)
ZIMMediaDownloadConfig config;
// 指定下载图片消息
config.messageInfoIndex = 1;

ZIM::getInstance()->downloadMediaFile(multipleMessage,
                                     ZIMMediaFileType::ZIM_MEDIA_FILE_TYPE_ORIGINAL_FILE,
// !mark(1:2)
                                     config,
                                     [=](const std::shared_ptr<ZIMMessage> &message, unsigned long long currentFileSize, unsigned long long totalFileSize) {
                                         // 下载进度
                                         // 开发者需要判断 message 的类型并转换成对应类型的消息
                                         if (message->getType() == ZIMMessageType::ZIM_MESSAGE_TYPE_MULTIPLE) {
                                             auto multipleMessage = std::static_pointer_cast<ZIMMultipleMessage>(message);
                                             // 处理组合消息
                                         }
                                         // 其他类型消息的处理
                                         ......
                                     },
// !mark
                                     [=](const std::shared_ptr<ZIMMessage> &message, const ZIMError &errorInfo) {
                                         // 下载完成
                                         // 开发者需要判断 message 的类型并转换成对应类型的消息
                                         if (message->getType() == ZIMMessageType::ZIM_MESSAGE_TYPE_MULTIPLE) {
                                             auto multipleMessage = std::static_pointer_cast<ZIMMultipleMessage>(message);
                                             // 处理组合消息
                                         }
                                         // 其他类型消息的处理
                                         ......
                                     });

sendMediaMessage

自 2.19.0 版本后,发送多媒体消息需使用 sendMessage 接口。sendMediaMessage 接口被废弃,以实现发送消息的统一性和便于后续的通用扩展。

auto imageMessage = std::static_pointer_cast<ZIMImageMessage>(message);
ZIMMessageSendConfig config;
config.priority = ZIMMessagePriority::ZIM_MESSAGE_PRIORITY_MEDIUM;

// !mark
auto notification = std::make_shared<ZIMMessageSendNotification>();
notification->onMessageAttached = [=](const std::shared_ptr<ZIMMessage> &message) {
    // 开发者可以监听这个回调执行消息发送前的业务逻辑
};
notification->onMediaUploadingProgress = [=](const std::shared_ptr<ZIMMediaMessage> &message, unsigned long long currentFileSize, unsigned long long totalFileSize) {
    // 多媒体上传进度
};

// !mark
ZIM::getInstance()->sendMessage(imageMessage, 
                               "TO_CONVERSATION_ID", 
                               ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER, 
                               config, 
                               notification, 
                               [=](const std::shared_ptr<ZIMMessage> &message, const ZIMError &errorInfo) {
                                   // 消息发送结果
                               });

2.18.0 升级指南

注意

从 2.18.0 版本开始,以下接口有重大变更,因此在从旧版本升级到 2.18.0 版本时,请您阅读以下指南。

单聊消息接收回调

原单聊消息接收回调 onReceivePeerMessage 已被废弃,请使用 onPeerMessageReceived 代替。

新回调支持以下功能:

  • 用户在线时,可通过此回调接收在线单聊消息。
  • 用户重新登录 ZIM SDK 后,可以通过此回调接收离线期间(最长7天)收到的所有单聊消息。
//新接口
virtual void 
onPeerMessageReceived(ZIM * /*zim*/, 
                        const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/,
                        const ZIMMessageReceivedInfo & /*info*/, 
                        const std::string & /*fromUserID*/) {}

//老接口
virtual void
onReceivePeerMessage(ZIM * /*zim*/,
                        const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/,
                        const std::string & /*fromUserID*/) {}

房间消息接收回调

原房间消息接收回调 onReceiveRoomMessage 已被废弃,请使用 onRoomMessageReceived 代替。

新回调支持以下功能:

  • 用户在线时,可通过此回调接收在线房间消息。
  • 用户从离线恢复到在线后,若仍在房间中,即可通过此回调接收离线期间内的所有房间消息。
//新接口
virtual void 
onRoomMessageReceived(ZIM * /*zim*/, 
                        const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/,
                        const ZIMMessageReceivedInfo & /*info*/, 
                        const std::string & /*fromRoomID*/) {}

//老接口
virtual void
onReceiveRoomMessage(ZIM * /*zim*/,
                        const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/,
                        const std::string & /*fromRoomID*/) {}

群组消息接收回调

原群组消息接收回调 onReceiveGroupMessage 已被废弃,请使用 onGroupMessageReceived 代替。

新回调支持以下功能:

  • 用户在线时,可通过此回调接收在线群组消息。
  • 用户重新登录 ZIM SDK 后,可以通过通过此回调接收离线期间(最长7天)收到的所有群聊消息。
//新接口
virtual void onGroupMessageReceived(ZIM * /*zim*/, 
                                        const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/,
                                        const ZIMMessageReceivedInfo & /*info*/, 
                                        const std::string & /*fromGroupID*/) {}
    
//老接口
virtual void onReceiveGroupMessage(ZIM * /*zim*/, 
                                    const std::vector<std::shared_ptr<ZIMMessage>> & /*messageList*/, 
                                    const std::string & /*fromGroupID*/) {}

2.16.0 升级指南

注意

从 2.16.0 版本开始,以下接口有重大变更,因此在从旧版本升级到 2.16.0 版本时,请您阅读以下指南。

callCancel

说明

以下变更仅对进阶模式呼叫邀请而言。

在新版本的 callCancel 中,如果参数 userIDs 包含一个 userID,则该接口将仅取消邀请该被叫用户。如果 userIDs 参数为空,则该接口将对所有被叫用户取消邀请。

而对于旧版本的 callCancel 接口,无论参数 userIDs 是否为空,均视为对所有被叫用户取消邀请。

由于旧版 ZIM SDK 不兼容单独取消逻辑,因此如果您既需要保留使用老版本 ZIM 实现的取消逻辑,又需要使用新版本的单独取消功能,请隔离新老版本 ZIM 之间的呼叫功能。

// 单独取消 userIdA 、userIdB
std::vector<std::string> invitees;
invitees.emplace_back("userIdA");
invitees.emplace_back("userIdB");
ZIMCallCancelConfig config;
zim->callCancel(invitees, "callID", config, [=](const std::string& callID, const std::vector<std::string>& errorInvitees,
    const ZIMError& errorInfo) {
});

// 取消整个呼叫邀请,当整个呼叫中所有被叫都未接受时可以调用成功    
std::vector<std::string> invitees;
ZIMCallCancelConfig config;
zim->callCancel(invitees, "callID", config, [=](const std::string& callID, const std::vector<std::string>& errorInvitees,
    const ZIMError& errorInfo) {
});

上一篇

ZIM

下一篇

ZIM

当前页

返回到顶部