打一个正式包,安装后测试
(直接运行到手机调试器是没有效果的,得到的cid 会显示该cid不是属于该应用)
在dcloud后台,该真机得到的cid
基本代码
msgPush() {
// 推送服务业务逻辑
//#ifdef APP-PLUS
// 进来时候先获取clientid存储起来,登录时候传递给后端
//client_id
this.$store.state.cache['client_id'] = plus.push.getClientInfo().clientid;
// console.log(plus.push.getClientInfo().clientid)
console.log('plus.push.getClientInfo()', plus.push.getClientInfo());
let timer = false;
/* 点击推送消息事件*/
plus.push.addEventListener('click', function(msg) {
// 点击跳转到指定路径
clearTimeout(timer);
timer = setTimeout(() => {
// console.log(1111,msg);
if (msg.payload) {
uni.navigateTo({
url: msg.payload
})
}
}, 1500)
});
// 监听在线消息事件
plus.push.addEventListener('receive', function(msg) {
console.log("recevice:" + JSON.stringify(msg))
// TODO
if ("LocalMSG" == msg.payload) {} else {
if (msg.type == 'receive') {
var options = {
cover: false,
title: msg.title
};
plus.push.createMessage(msg.content, msg.payload, options);
}
}
});
//#endif
},