百倍
百倍
  • 发布:2022-06-12 15:27
  • 更新:2022-06-12 15:27
  • 阅读:2124

uniapp 第一次安装,获取的plus.push.getClientInfo().clientid为null的解决方案

分类:uni-app

App.vue

<script>  
    export default {  
        onLaunch: function() {  
            console.log('App Launch');  

            // 第一次安装,获取的设备信息clientid为null  
            // 用于解决plus.push.getClientInfo同步获取可能返回数据为空的问题  
            // 要延迟一点时间获取,具体延迟多长不确定。使用以下代码解决  
            var t1 = setInterval(() => {    
                var info = plus.push.getClientInfo();  
                var clientid = info.clientid; // 注意:clientid为空时,返回的是字符串"null"  
                if(clientid && clientid != "null") {  
                    console.log(clientid) // 客户端标识  
                    clearInterval(t1);  
                }  
            },50);  

        }  
    };  
</script>
0 关注 分享

要回复文章请先登录注册