huiyichengyi
huiyichengyi
  • 发布:2015-05-14 10:31
  • 更新:2015-05-14 11:06
  • 阅读:4296

【报bug】发送普通消息为啥不执行click事件?是bug茫

分类:HTML5+

我是android平台的,我在发普通消息时,客户端收到消息了,但是点击后没有触发我的click事件,按照api上他应该执行我的click事件啊?为啥没执行
但是我发透传数据消息是如果透传消息格式是正确的执行click事件,发送不符合格式的透传消息执行revice事件这个是和API相符的
=================================================
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="HandheldFriendly" content="true"/>
<meta name="MobileOptimized" content="320"/>
<title>Hello H5+</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
var pushServer = "http://demo.dcloud.net.cn/helloh5/push/";
var message = null;
// 监听plusready事件
document.addEventListener( "plusready", function(){
message = document.getElementById("message");
// 监听点击消息事件
plus.push.addEventListener( "click", function( msg ) {
// 判断是从本地创建还是离线推送的消息
alert("click");
switch( msg.payload ) {
case "LocalMSG":
outSet( "点击本地创建消息启动:" );
break;
default:
outSet( "点击离线推送消息启动:");
break;
}
// 提示点击的内容
plus.nativeUI.alert( msg.content );
// 处理其它数据

    logoutPushMsg( msg );  
     console.log("click:"+JSON.parse(msg));  
}, false );  
// 监听在线消息事件  
plus.push.addEventListener( "receive", function( msg ) {  

    alert(msg.aps+"revice");  
    if ( msg.aps ) {  // Apple APNS message  
        outSet( "接收到在线APNS消息:" );  
    } else {  
        outSet( "接收到在线透传消息:" );  
    }  
    logoutPushMsg( msg );  
    console.log("revice:"+JSON.parse(msg));  
}, false );  

}, false );

/**

  • 日志输入推送消息内容
    */
    function logoutPushMsg( msg ) {
    outLine( "title: "+msg.title );
    outLine( "content: "+msg.content );
    if ( msg.payload ) {
    if ( typeof(msg.payload)=="string" ) {
    outLine( "payload(String): "+msg.payload );
    } else {
    outLine( "payload(JSON): "+JSON.stringify(msg.payload) );
    }
    } else {
    outLine( "payload: undefined" );
    }
    if ( msg.aps ) {
    outLine( "aps: "+JSON.stringify(msg.aps) );
    }
    }

/**

  • 获取本地推送标识信息
    */
    function getPushInfo(){
    var info = plus.push.getClientInfo();
    outSet( "获取客户端推送标识信息:" );
    outLine( "token: "+info.token );
    outLine( "clientid: "+info.clientid );
    outLine( "appid: "+info.appid );
    outLine( "appkey: "+info.appkey );
    }
    /**
  • 本地创建一条推动消息
    /
    function createLocalPushMsg(){
    var options = {cover:false};
    var str = dateToStr(new Date());
    str += ": 欢迎使用Html5 Plus创建本地消息!";
    plus.push.createMessage( str, "LocalMSG", options );
    outSet( "创建本地消息成功!" );
    outLine( "请到系统消息中心查看!" );
    if(plus.os.name=="iOS"){
    outLine('
    如果无法创建消息,请到"设置"->"通知"中配置应用在通知中心显示!');
    }
    }
    /**
  • 读取所有推送消息
    */
    function listAllPush(){
    var msgs=null;
    switch ( plus.os.name ) {
    case "Android":
    msgs = plus.push.getAllMessage();
    break;
    default:
    break;
    }
    if ( !msgs ) {
    outSet( "此平台不支持枚举推送消息列表!" );
    return;
    }
    outSet( "枚举消息列表("+msgs.length+"):" );
    for ( var i in msgs ) {
    var msg = msgs[i];
    outLine( i+": "+msg.title+" - "+msg.content );
    }
    }
    /**
  • 清空所有推动消息
    */
    function clearAllPush(){
    plus.push.clear();
    outSet( "清空所有推送消息成功!" );
    }
    /**
  • 请求‘简单通知’推送消息
    */
    function requireNotiMsg(){
    var url = pushServer+'notiPush.php?appid='+encodeURIComponent(plus.runtime.appid);
    url += ('&cid='+encodeURIComponent(plus.push.getClientInfo().clientid));
    console.log(plus.push.getClientInfo().clientid);
    url += ('&title='+encodeURIComponent('Hello H5+'));
    url += ('&content='+encodeURIComponent('欢迎回来体验HTML5 plus应用!'));
    url += ('&version='+encodeURIComponent(plus.runtime.version));
    console.log(url);
    plus.runtime.openURL( url );
    }
    /**
  • 请求‘打开网页’推送消息
    */
    function requireLinkMsg(){
    var url = pushServer+"linkPush.php?appid="+encodeURIComponent(plus.runtime.appid);
    url += ('&cid='+encodeURIComponent(plus.push.getClientInfo().clientid));
    url += ('&title='+encodeURIComponent('HBuilder飞一样的编码'));
    url += ('&content='+encodeURIComponent('看HBuilder如何追求代码编写速度的极致!立即去瞧一瞧?'));
    url += ('&url='+encodeURIComponent('http://www.dcloud.io/'));
    url += ('&version='+encodeURIComponent(plus.runtime.version));
    plus.runtime.openURL( url );
    }
    /**
  • 请求‘下载链接’推送消息
    */
    function requireDownMsg(){
    if ( plus.os.name != "Android" ) {
    plus.nativeUI.alert( "此平台不支持!" );
    return;
    }
    var url = pushServer+'downPush.php?appid='+encodeURIComponent(plus.runtime.appid);
    url += ('&cid='+encodeURIComponent(plus.push.getClientInfo().clientid));
    url += ('&title='+encodeURIComponent('Hello H5+'));
    url += ('&content='+encodeURIComponent('新版本发布了!立即下载体验?'));
    url += ('&poptitle='+encodeURIComponent('Hello H5+'));
    url += ('&popcontent='+encodeURIComponent('1. 优化用户体验;\n2. 修复在Android2.3.x某些设备可能异常退出的问题.'));
    url += ('&downtitle='+encodeURIComponent('下载Hello H5+'));
    url += ('&downurl='+encodeURIComponent('http://d.m3w.cn/helloh5p/HelloH5.apk'));
    url += ('&version='+encodeURIComponent(plus.runtime.version));
    plus.runtime.openURL( url );
    }
    /**
  • 请求‘透传数据’推送消息
    */
    function requireTranMsg(){

    var url = pushServer+'tranPush.php?appid='+encodeURIComponent(plus.runtime.appid);
    url += ('&cid='+encodeURIComponent(plus.push.getClientInfo().clientid));
    url += ('&title='+encodeURIComponent('Hello H5+'));
    url += ('&content='+encodeURIComponent('带透传数据推送通知,可通过plus.push API获取数据并进行业务逻辑处理!'));
    url += ('&payload='+encodeURIComponent('{title:"Hello H5+ Test",content:"test content",payload:{id:"1234567890"}}'));
    url += ('&version='+encodeURIComponent(plus.runtime.version));
    plus.runtime.openURL( url );
    }
    </script>
    <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
    </head>
    <body>
    <header>
    <div class="nvbt iback" onclick="back(true);"></div>
    <div class="nvtt">Push</div>
    <div class="nvbt idoc" onclick="openDoc('Push Document','/doc/push.html')"></div>
    </header>
    <div id="dcontent" class="dcontent">
    <div class="button" onclick="requireNotiMsg();">发送"普通通知"消息</div>
    <div class="button" onclick="requireLinkMsg();">发送"打开网页"消息</div>
    <div class="button" onclick="requireDownMsg();">发送"下载链接"消息</div>
    <div class="button" onclick="requireTranMsg();">发送"透传数据"消息</div>
    <br/>
    <ul id="dlist" class="dlist">
    <li class="ditem" onclick="getPushInfo();">获取客户端推送标识</li>
    <li class="ditem" onclick="createLocalPushMsg();">创建本地消息</li>
    <li class="ditem" onclick="listAllPush();">枚举推送消息(Android)</li>
    <li class="ditem" onclick="clearAllPush();">清空推送消息</li>
    </ul>
    </div>
    <div id="output">
    Push模块管理推送消息功能,可以实现在线、离线的消息推送,通过plus.push可获取推送消息管理对象。
    </div>
    </body>
    </html>

2015-05-14 10:31 负责人:无 分享
已邀请:
huiyichengyi

huiyichengyi (作者)

个推技术支持 :
普通消息的通知栏点击事件你们客户端不能处理的,获取不到onclick事件的
透传消息客户端处理成通知栏展示后,onclick事件是可以获取到的
普通消息的通知栏展示是我们SDK内部处理的,点击事件你们是获取不到的
只用透传吧

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