前言
功能
- 设置桌面图标icon角标消息数量
- 清除桌面图标icon角标消息数量
接入步骤
如不了解原生插件接入步骤的同学请参考:
https://www.jianshu.com/p/830ccc503e29
或 https://blog.csdn.net/wenrisheng/article/details/124057700
介绍
- 接口
var badge = uni.requireNativePlugin("wrs-badge");
- 设置桌面图标icon角标消息数量
badge.setBadge({
"num": 2
});
- 清除桌面图标icon角标消息数量
badge.clearBadge();
- ios如果角标设置不生效,请先调用registerUserNotificationSettings,如果集成了极光推送或个推等第三方消息推送平台一般角标设置都会生效,具体取决于项目配置或基座版本
switch (uni.getSystemInfoSync().platform) {
case 'ios':
// type:
// 0:UIUserNotificationTypeNone the application may not present any UI upon a notification being received
// 1:UIUserNotificationTypeBadge he application may badge its icon upon a notification being received
// 2:UIUserNotificationTypeSound the application may play a sound upon a notification being received
// 3:UIUserNotificationTypeAlert the application may display an alert upon a notification being received
badge.registerUserNotificationSettings({
"types": 1 | 2 | 3
}, (resp)=>{
if(resp.granted) {
} else {
}
});
break;
default:
break;
}
- Android由于碎片化太严重,各个厂家和版本都高度定制化,不一定支持所有版本,以下机型应该问题不大