代码一:
uni.onPushMessage((res) => {
console.log("收到推送消息:",res) //监听推送消息
let pushToUrl = '';
if (res.type == 'receive') {
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
payload: res.data.payload,
})
}
})
代码二:
plus.push.addEventListener("receive", function(msg) {
console.log("recevice:" ,msg)
// if (msg.aps) { // Apple APNS message
// //APNS下发的消息,应用在前台
// plus.push.createMessage(msg.content, msg.payload, {
// title: msg.title
// });
// } else if (msg.type != "receive") { // 特殊payload标识本地创建的消息
// //本地创建的消息,通常不需要处理
// //注意:不要在这种情况下再此调用plus.push.createMessage,从而引起循环创建本地消息
// } else {
// //接收到在线透传消息
// plus.push.createMessage(msg.content, msg.payload, {
// title: msg.title
// });
// }
if (msg.type) {
plus.push.createMessage(msg.content, msg.payload, {
title: msg.title
});
}
}, false);
以上代码都是点击闪退
pushuo (作者)
content 确实是空的,我是在 dcloud 后台 uniPush 发送的推送消息,通知标题 和 通知内容 都写了,但是接受到的推送没有这些。 这个是接受到的json {
"type": "receive",
"data": {
"aps": null,
"content": "",
"payload": "",
"title": "JC food",
"type": "receive"
}
}
2022-12-19 09:18
DCloud_iOS_WZT
回复 2***@qq.com: 我记得有几项是必填的 你不要传空
2022-12-19 11:49
pushuo (作者)
回复 DCloud_iOS_WZT: 这就是我奇怪的地方,通知标题 和 通知内容 都写了,必填项都填写了,收到的推送也没有这些内容。很奇怪,你可以试一下 通过 dcloud 后台 uniPush 发送推送消息
2022-12-19 11:56