zhaojs
2023-07-13 70f5b82bc3fceafac2faf470280876b0eca6fac8
uniapp/App.vue
@@ -13,10 +13,11 @@
      onLaunch: function() {
         // #ifdef APP-PLUS
         //推送开始
         var info = plus.push.getClientInfo()
         /* var info = plus.push.getClientInfo()
         console.log(info);
         // 获取当前设备的客户端id,传给后台,实现指定用户
         info && uni.setStorageSync('clientInfo', info)
         info && uni.setStorageSync('clientInfo', info) */
         this.getPushCid();
         // 使用5+App的方式进行监听消息推送
         //消息点击事件  
         //【APP在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。  
@@ -57,6 +58,7 @@
         //收到透传消息  
         //只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息  
         plus.push.addEventListener("receive", function(msg) {
            console.log('receive', JSON.stringify(msg))
            //业务代码
            // IOS
            if (uni.getSystemInfoSync().platform == 'ios') {
@@ -154,7 +156,6 @@
                     content: '检测到网络权限可能设置为关闭,您可以在“设置”中检查无线数据及蜂窝移动网络'
                  })
               }else{
                  console.log("是否请求过:"+that.globalData.hasinit)
                  if(!that.globalData.hasinit)
                  {
                     that.getAppInfo();
@@ -189,11 +190,9 @@
          bcInit:function()
         {
            var that = this;
            console.log(uni.getSystemInfoSync().platform);
            if (uni.getSystemInfoSync().platform == 'ios')
            {
               const plug = uni.requireNativePlugin('xiguazhu-baichuan');
               console.log(plug)
               plug.init({}, result => {
                  //console.log('1111111111111111111');
                  console.log(result);   // code等于0就是初始化成功
@@ -206,6 +205,40 @@
            else{
               that.globalData.hasbcinit=true;
            }
         },
         getPushCid:function()
         {
            // #ifdef APP-PLUS
            var info = plus.push.getClientInfo()
            if(info&&info.clientid!='null')
            {// 获取当前设备的客户端id,传给后台,实现指定用户
               uni.setStorageSync('clientInfo', info);
               this.updatePushCid();
            }
            else{
               console.log('没有获取到');
               setTimeout(() => {
                  this.getPushCid();
               }, 1000)
            }
            // #endif
         },
         updatePushCid:function()
         {
            let clientInfo = uni.getStorageSync('clientInfo');
            if(clientInfo&&clientInfo!='null'&&clientInfo.clientid)
            {
               console.log('开始更新');
               this.$u.api.updateCid({
                  pushcid:clientInfo.clientid
               }).then(e => {
               }).catch(function (err) {
               })
            }
            else{
               this.getPushCid();
            }
         },
         getAppInfo: function() {
            var that = this;
@@ -238,7 +271,6 @@
                  if (plus.runtime.isApplicationExist({pname:'com.tencent.mm',
                        action: 'weixin://'
                     })) {
                        console.log("安卓端已安装微信")
                     that.globalData.ifwt = 1 //是否安装微信 1代表安装
                  } else {
                     console.log("安卓端未安装微信")