3***@qq.com
3***@qq.com
  • 发布:2021-08-05 15:29
  • 更新:2021-08-05 15:29
  • 阅读:384

使用web2app打包的壳推送的时候华为可以接收推送,但点击后不触发click和receive事件,别的品牌正常???

分类:wap2app

产品分类: 其他/wap2app

示例代码:

var info = null;  
//app下载地址  
var appDownloadUrl="https://o2";  
if (window.plus) {  
  plusReady()  
} else {  
  document.addEventListener('plusready', plusReady, false)  
}  
function plusReady() {  
  // App壳版本控制开始  
  if(window.config.SHELL_VERSION_VERIFY){  
    var versionCode =  plus.runtime.versionCode  
    if(versionCode){  
      if(versionCode < window.config.SHELL_VERSION_CODE ){  //版本号对应壳中版本versionCode  
        Dialog.alert({  
          title: '更新提示',  
          message: '当前版本 '+versionCode+',发现新版本快去更新吧!',  
          theme: 'round-button',  
          confirmButtonText:'更新'  
        }).then(() => {  
          plus.runtime.openURL( appDownloadUrl , errorCB);  
        });  
      }  
    }  
  }  

  // App壳版本控制结束  
  getClientInfo();  
}  

function errorCB(error){  
  alert("调用浏览器失败,error:"+error);  
}  

function getClientInfo() {  
  // 扩展API加载完毕,现在可以正常调用扩展API  
  // 获取客户端标识信息  
  info = plus.push.getClientInfo();  
  alert('info: '+JSON.stringify(info));  
  if(info || info.clientid!='null' || info.token!='null'){  
    alert('cid: '+JSON.stringify(info));  
    localStorage.pushClientId = info.clientid;  
    localStorage.pushToken = info.token;  
    // 添加监听从系统消息中心点击消息启动事件  
    plus.push.addEventListener('click', function(msg){  
      alert('You clicked: '+JSON.stringify(msg));  
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
     //var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
     var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
     if(msg){  
     // alert("c"+JSON.stringify(msg));  
       if(isiOS){  
         if(msg.payload.iosParame){  
            localStorage.pushParam=msg.payload.iosParame;  
            router.push({  
              path: "/toIndex"  
              });  
         }else if(msg.payload){  
          alert("我进入跳转了"+msg.payload);  
            localStorage.pushParam=msg.payload;  
            router.push({  
              path: "/toIndex"  
              });  
         }  
       }  
     }  
    }, false);  
    plus.push.addEventListener('receive', function(msg){  
      alert('You receive: '+ JSON.stringify(msg));    
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
      var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
      if(msg){  
       // alert("r"+JSON.stringify(msg));  
        if(isiOS){  
          if(msg.aps){  
            const payload=msg.payload.iosParame;  
          const option={};  
            option.title=msg.aps.alert.title;  
          const content=msg.aps.alert.body;  
          void plus.push.createMessage( content,payload,option );  
          }  
        }else if(isAndroid){  
          alert('You receive: 进入安卓'+ JSON.stringify(msg.payload));    
          if(msg.payload){  
            localStorage.pushParam=JSON.stringify(msg.payload);  
            router.push({  
              path: "/toIndex"  
              });  
          }  
        }  
      }  
    }, false);  

    if(int!=null){  
       window.clearInterval(int);  
    }  
  }else{  
    if(int==null){  
       int=self.setInterval("getClientInfo()",1000);  
    }  
  }  
}```   

操作步骤:

web2app集成unipush发送推送,使用华为手机接收点击消息出现bug不触发click和receive事件 下面两个监听失效

      alert('You receive: '+ JSON.stringify(msg));    
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
      var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
      if(msg){  
       // alert("r"+JSON.stringify(msg));  
        if(isiOS){  
          if(msg.aps){  
            const payload=msg.payload.iosParame;  
          const option={};  
            option.title=msg.aps.alert.title;  
          const content=msg.aps.alert.body;  
          void plus.push.createMessage( content,payload,option );  
          }  
        }else if(isAndroid){  
          alert('You receive: 进入安卓'+ JSON.stringify(msg.payload));    
          if(msg.payload){  
            localStorage.pushParam=JSON.stringify(msg.payload);  
            router.push({  
              path: "/toIndex"  
              });  
          }  
        }  
      }  
    }, false);  
  plus.push.addEventListener('click', function(msg){  
      alert('You clicked: '+JSON.stringify(msg));  
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
     //var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
     var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
     if(msg){  
     // alert("c"+JSON.stringify(msg));  
       if(isiOS){  
         if(msg.payload.iosParame){  
            localStorage.pushParam=msg.payload.iosParame;  
            router.push({  
              path: "/toIndex"  
              });  
         }else if(msg.payload){  
          alert("我进入跳转了"+msg.payload);  
            localStorage.pushParam=msg.payload;  
            router.push({  
              path: "/toIndex"  
              });  
         }  
       }  
     }  
    }, false);  

预期结果:

华为手机点击推送消息触发click和receive事件回调

实际结果:

web2app集成unipush发送推送,使用华为手机接收点击消息出现bug不触发click和receive事件 下面两个监听失效

      alert('You receive: '+ JSON.stringify(msg));    
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
      var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
      if(msg){  
       // alert("r"+JSON.stringify(msg));  
        if(isiOS){  
          if(msg.aps){  
            const payload=msg.payload.iosParame;  
          const option={};  
            option.title=msg.aps.alert.title;  
          const content=msg.aps.alert.body;  
          void plus.push.createMessage( content,payload,option );  
          }  
        }else if(isAndroid){  
          alert('You receive: 进入安卓'+ JSON.stringify(msg.payload));    
          if(msg.payload){  
            localStorage.pushParam=JSON.stringify(msg.payload);  
            router.push({  
              path: "/toIndex"  
              });  
          }  
        }  
      }  
    }, false);  
  plus.push.addEventListener('click', function(msg){  
      alert('You clicked: '+JSON.stringify(msg));  
      plus.runtime.setBadgeNumber(0);  
     var u = plus.navigator.getUserAgent()  
     //var isAndroid = u.indexOf('Android') > -1 ; //android终端或者uc浏览器  
     var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
     if(msg){  
     // alert("c"+JSON.stringify(msg));  
       if(isiOS){  
         if(msg.payload.iosParame){  
            localStorage.pushParam=msg.payload.iosParame;  
            router.push({  
              path: "/toIndex"  
              });  
         }else if(msg.payload){  
          alert("我进入跳转了"+msg.payload);  
            localStorage.pushParam=msg.payload;  
            router.push({  
              path: "/toIndex"  
              });  
         }  
       }  
     }  
    }, false);  

bug描述:

您好我使用web2app打包的壳推送的时候华为可以接收推送,但点击后不触发click和receive事件,别的品牌正常???

2021-08-05 15:29 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复