表现:推送过程中,IOS系统通知栏里除了当下推送的信息外还自动添加了之前推送过的信息
备注:安卓版没有这样的情况,有遇到类似问题的道友们支个招,小菜这厢有礼了
代码:
if(plus.os.name!='Android'){
console.log('开始清空消息');
plus.runtime.setBadgeNumber(0);
var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
GeTuiSdk.setBadge(0);
// plus.push.clear();
console.log('清空消息结束');
}
plus.push.addEventListener('click', function(msg) {
var contentJson;
var noticeId;
if(typeof(msg.payload)=='string'){
noticeId = JSON.parse(msg.payload).sourceId;
}else{
noticeId = msg.payload.sourceId;
}
if(uni.getSystemInfoSync().platform == 'ios'){
ontentJson = msg.payload;
//------页面跳转前置工作,省略代码
var UIApplication = plus.ios.import("UIApplication");
var app = UIApplication.sharedApplication();
// 获取应用图标的数量
var oldNum = app.applicationIconBadgeNumber();
if(oldNum!=0){
var newNum = oldNum - 1;
// 设置应用图标的数量
plus.runtime.setBadgeNumber(newNum);
// 导入个推原生类
var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
GeTuiSdk.setBadge(newNum);
}
}else{
var reg = new RegExp(/\\/g);
var content = msg.payload.replace(reg, "\\\\");
contentJson = JSON.parse(content);
}
//------页面跳转处理,省略代码
},false);
plus.push.addEventListener('receive', function(msg) {
if(uni.getSystemInfoSync().platform == 'ios') { // Apple APNS message
var payload = msg.payload;
if (msg.aps == null && msg.type == "receive") {
var messageTitle = payload.title;
var messageContent = payload.content;
plus.push.createMessage(messageContent, JSON.stringify(payload), {
title: messageTitle,
cover: false
});
}
} else {///------安卓相关代码,省略代码}
},false);
1 个回复
DCloud_uniCloud_JSON
请参考插件 https://ext.dcloud.net.cn/plugin?id=1680