app已经上线,具体使用已经忘记了,今天把代码发出来,希望能帮助有需要的同学,请大家多多批评
其中主要的功能主要写在了 App.vue文件的onLaunch 方法
代码示例
console.log('App Launch')
//推送
//#ifdef APP-PLUS
//plus.push.createMessage('你已经打开了app');
plus.globalEvent.addEventListener('netchange', function() {
console.log('----------------网络发生变化----------')
});
var info = plus.push.getClientInfo();
console.log(JSON.stringify(info));
if (info.clientid) {
uni.setStorageSync('clientid', info.clientid)
}
/* 5+ push 消息推送 ps:使用:H5+的方式监听,实现推送*/
plus.push.addEventListener("click", function(msg) {
console.log("click:" + JSON.stringify(msg));
console.log('------------msg.payload------------------')
console.log(msg.payload);
console.log(JSON.stringify(msg));
var pages = getCurrentPages();
var page = pages[pages.length - 1];
console.log(pages.length)
console.log('--------当前页面名称-------------');
let payload;
if(msg.aps){
payload = JSON.parse(msg.aps.category)
}else{
payload = JSON.parse(msg.payload)
}
if (payload.type == 'test') {
if (pages.length == 0) {
uni.navigateTo({
url: 'pages/index/test1?param=bai'
})
} else {
uni.navigateTo({
url: 'test1?param=bai'
})
}
}
}, false);
// 监听在线消息事件
plus.push.addEventListener("receive", function(msg) {
// plus.ui.alert(2);
//这里可以写跳转业务代码
console.log("recevice:" + JSON.stringify(msg))
let payload = msg.payload;
console.log(payload)
var options = {cover:false};
if(msg.type=='receive'){
plus.push.createMessage(payload.content, JSON.stringify(payload), options);
}
}, false);
//#endif
源代码地址:https://gitee.com/meta_intelligence/push_demo/tree/master