Trust
Trust
  • 发布:2019-03-22 17:45
  • 更新:2025-02-20 17:58
  • 阅读:104056

在 uni-app 中使用 uni-push

分类:uni-app
22 关注 分享
Geeker 小张没有名字 1***@qq.com 今天回复我了吗 正儿八经吃豆腐 Panda_2012 5***@qq.com 5***@qq.com 4***@qq.com coolfires n***@yeah.net 9***@qq.com 河南dev 霜序一七 jtshushu aliang888 一个网名 rysnone b***@163.com 6***@qq.com 1***@qq.com 全栈工程师Rone

该文章目前已经被锁定, 无法添加新评论

5***@qq.com

5***@qq.com

good
2020-12-02 11:55
westgogo

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
云鹏

云鹏

一模一样的代码,啥也收不到,心累
2020-10-23 23:01
w***@hotmail.com

w***@hotmail.com

plus is not defined怎么办
2020-09-28 10:57
9***@qq.com

9***@qq.com

回复 2***@qq.com :
首先你要确认你的推送检测到了,也就是到了_handlePush里面 先show点东西出来建议用uni.showModal uni.showToast的话可能你没加载完首页已经显示过了 ,看不到show的内容 如果也能show出来东西 说明进入了_handlePush处理方法 此时处理页面跳转 如果路径没问题的话 也不是tabbar页面 给路由加个延时 试试
2020-08-21 09:23
2***@qq.com

2***@qq.com

onLaunch: function() {
// #ifdef APP-PLUS
const _self = this;
const _handlePush = function(message) {
uni.navigateTo({
url: '/pages/map_order/index',
});
uni.showToast({
title: JSON.stringify(message)+''
});
};
plus.push.addEventListener('click', _handlePush);
plus.push.addEventListener('receive', _handlePush);
// #endif

},
推送成功,点击不会跳转。
2020-08-18 08:28
小雨_0128

小雨_0128

有谁知道这个问题怎么解决吗?

https://ask.dcloud.net.cn/question/102873
2020-07-31 13:49
3***@qq.com

3***@qq.com

回复 3***@qq.com :
搞定了,传了透传信息后要用receive才能接收到
2020-07-29 09:15
3***@qq.com

3***@qq.com

回复 3***@qq.com :
谢谢老铁
2020-07-27 21:33
3***@qq.com

3***@qq.com

NotificationTemplate template = new NotificationTemplate();
template.setAppId(APPID);
template.setAppkey(APPKEY);
template.setStyle(PushStyle.getStyle6(title,text));

template.setTransmissionType(1); // 透传消息设置,收到消息是否立即启动应用: 1为立即启动,2则广播等待客户端自启动
template.setTransmissionContent(url);
我这边setTransmissionType设置1的时候不会立即启动应用,点了之后才会启动应用,设置2的话,点了之后都不会启动应用,然后setTransmissionContent设置的值在前端取不到
plus.push.addEventListener('click', function(message) {
uni.showToast({
title: "111111",
icon: 'none',
duration: 3000
})
uni.showToast({
title: message.payload,
icon: 'none',
duration: 3000
})
uni.navigateTo({
url: message.payload
});
});
这么写可以看到message.payload里面只有title和content
请问我该怎么取到setTransmissionContent设置的值
2020-07-24 17:01