chenhaozhe
2026-03-16 9cf8c49dcf960743f22baaec737bfb0c134d5683
ios 调整clientiD 获取逻辑
2个文件已修改
57 ■■■■ 已修改文件
manifest.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/getuiUtils.js 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manifest.json
@@ -2,8 +2,8 @@
    "name" : "智云LMES",
    "appid" : "__UNI__B002F49",
    "description" : "",
    "versionName" : "2.094",
    "versionCode" : 294,
    "versionName" : "2.095",
    "versionCode" : 295,
    "transformPx" : false,
    /* 5+App特有相关 */
    "app-plus" : {
utils/getuiUtils.js
@@ -9,13 +9,56 @@
    getClientID(Userbm, UserName) {
        // #ifdef APP-PLUS
        const info = plus.push.getClientInfo()
        this.cid = info["clientid"]
        console.log('cid: ', this.cid);
        this.setUserClientIDRelative(Userbm, UserName, this.cid, 1)
        // #endif
        // 定义重试参数:最多重试5次,每次间隔1.5秒(可根据实际情况调整)
        const maxRetry = 5;
        const retryInterval = 1500;
        let retryCount = 0;
        // 封装获取clientid的核心逻辑
        const tryGetClientId = () => {
            try {
                const info = plus.push.getClientInfo();
                // 兼容iOS不同SDK版本的字段名(clientid / clientId)
                const clientid = info?.clientid || info?.clientId;
                // 成功获取到clientid
                if (clientid) {
                    this.cid = clientid;
                    console.log('成功获取cid: ', this.cid);
                    this.setUserClientIDRelative(Userbm, UserName, this.cid, 1);
                    return;
                }
                // 未获取到,且还有重试次数
                if (retryCount < maxRetry) {
                    retryCount++;
                    console.log(`第${retryCount}次重试获取cid(暂未获取到),剩余重试次数:${maxRetry - retryCount}`);
                    setTimeout(tryGetClientId, retryInterval);
                    return;
                }
                // 重试耗尽仍未获取到
                console.error('重试次数耗尽,iOS环境下未获取到clientid');
                this.cid = '';
                // 可选:此处可添加获取失败的兜底逻辑(比如记录日志、提示用户等)
                this.setUserClientIDRelative(Userbm, UserName, this.cid, 1);
            } catch (error) {
                console.error('获取clientid过程中出现异常:', error);
                if (retryCount < maxRetry) {
                    retryCount++;
                    setTimeout(tryGetClientId, retryInterval);
                }
            }
    };
        // 启动第一次获取
        tryGetClientId();
        // #endif
    }
    async setUserClientIDRelative(Userbm, UserName, ClientID, Online) {
        try {
            let res = await CommonUtils.doRequest2Async({