uni-app 发送普通消息为何不执行click事件?是bug吗

uni-app 发送普通消息为何不执行click事件?是bug吗

Android平台问题

我是android平台的,我在发普通消息时,客户端收到消息了,但是点击后没有触发我的click事件,按照api上他应该执行我的click事件啊?为啥没执行

但是我发透传数据消息是如果透传消息格式是正确的执行click事件,发送不符合格式的透传消息执行revice事件这个是和API相符的

=================================================

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));
    url += ('&title='+encodeURIComponent('Hello H5+'));
    url += ('&content='+encodeURIComponent('欢迎回来体验HTML5 plus应用!'));
    url += ('&version='+encodeURIComponent(plus.runtime.version));
    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 );
}

操作按钮

  • 发送"普通通知"消息
  • 发送"打开网页"消息
  • 发送"下载链接"消息
  • 发送"透传数据"消息

其他操作

  • 获取客户端推送标识
  • 创建本地消息
  • 枚举推送消息(Android)
  • 清空推送消息

Push模块说明

Push模块管理推送消息功能,可以实现在线、离线的消息推送,通过plus.push可获取推送消息管理对象。


更多关于uni-app 发送普通消息为何不执行click事件?是bug吗的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app 发送普通消息为何不执行click事件?是bug吗的实战教程也可以访问 https://www.itying.com/category-93-b0.html


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

回到顶部