Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

h5+ push 做webapp消息推送,能推送消息,但是点击消息没有触发监听事件

//点击推送消息
createLocalPushMsg(){
    var options = {cover:false};
    var str = this.formatDate(new Date().getTime())
    str += ": 欢迎使用HTML5+创建本地消息!";
    plus.push.createMessage( str, "LocalMSG", options );
    console.log( "创建本地消息成功!" );
    console.log( "请到系统消息中心查看!" );
},
//监听消息点击事件
// 监听plusready事件  
    document.addEventListener( "plusready", function(){
        console.log('+++++++++++++++++++')
        message = document.getElementById("message");
        // 监听点击消息事件
        plus.push.addEventListener( "click", function( msg ) {
            console.log(22222)
            // 判断是从本地创建还是离线推送的消息
            switch( msg.payload ) {
                case "LocalMSG":
                    console.log( "点击本地创建消息启动:" );
                break;
                default:
                    console.log( "点击离线推送消息启动:");
                break;
            }
            // 提示点击的内容
            plus.nativeUI.alert( msg.content );
            // 处理其它数据
            // this.logoutPushMsg( msg );
        }, false );
        // 监听在线消息事件
        plus.push.addEventListener( "receive", function( msg ) {
            if ( msg.aps ) {  // Apple APNS message
                console.log( "接收到在线APNS消息:" );
            } else {
                console.log( "接收到在线透传消息:" );
            }
            this.logoutPushMsg( msg );
        }, false );
    }, false );

下面这个监听事件是要写在哪里?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

百度其他大佬提供的方案:https://ask.dcloud.net.cn/que...
直接用 H5+ 的 document.addEventListener('plusready', fn) 在加载时是没有问题的,
但是 mui 加载是比H5要延迟


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...