westgogo
写在APP onLaunch 中没有效果,写在具体的某个页面,却可以。搞不懂。
App.vue
```
onLaunch: function () {
console.log('App Launch');
// #ifdef APP-PLUS
const _self = this;
const _handlePush = function (message) {
console.log(message);
if (typeof message.payload === 'string') {
message.payload = JSON.parse(payload);
}
/**
* 约定 payload 格式
* type: [naviagte switchTab , web-view] 目前只支持这三种
* path: type 为 [naviagte , switchTab,web-view] 生效
* params: String , 附加参数,如:a=1&b=2 页面跳转,则作为 url 参数传递 ,并使用 encodeURIComponent 编码,固定参数名为 payload
*
*
*
*/
message.payload = message.payload || {};
console.log(message);
};
// IOS端在客户端在运行时收到推送消息触发receive事件,离线接收到的推送消息全部进入系统消息中心。点击消息中心的消息触发click
// Android 端
// 1. 透传消息
// 若符合 {title,content,payload} 类型,则不会触发 receive 事件 , 只会显示通知栏,点击通知栏,触发 click 事件
// 若不符合格式,则触发 receive 事件,且不会显示到通知栏,并且message对象的 payload 字段将自动填充为 {title,content}
// 2. 通知消息
// 点击通知栏消息, 触发 click 事件, message 将被 包装为 {title,content,payload} ,其中 payload = {title,content}
plus.push.addEventListener('click', function (message) {
WJF.ui.alert.successTip('push click');
console.log('app push click');
_handlePush(message);
});
plus.push.addEventListener('receive', function (message) {
WJF.ui.alert.successTip('push receive');
console.log('app push receive');
_handlePush(message);
});
console.log('============消息注册完毕=========')
// #endif
},
```
pages/push/index.vue
```
listenTranMsg () {
// IOS端在客户端在运行时收到推送消息触发receive事件,离线接收到的推送消息全部进入系统消息中心。点击消息中心的消息触发click
plus.push.addEventListener('click', (msg) => {
console.log('click listener ');
console.log(msg);
this.tranMsg = JSON.stringify(msg)
});
plus.push.addEventListener('receive', (msg) => {
console.log('receive listener ');
console.log(msg);
this.tranMsg = JSON.stringify(msg)
});
uni.showToast({
title: '开始监听透传数据',
icon: 'success'
});
},
```
代码没有区别,搞不懂为啥 具体的页面中可以,onLaunch不行
2020-11-11 09:36
78 个评论
该文章目前已经被锁定, 无法添加新评论
5***@qq.com
westgogo
云鹏
w***@hotmail.com
9***@qq.com
2***@qq.com
小雨_0128
3***@qq.com
3***@qq.com
3***@qq.com