uniAPP 角标清零
时间: 2024-04-25 13:23:19 浏览: 218
角标系统设计思路
uniAPP角标清零的方法可以根据不同的平台进行设置。对于iOS平台,可以使用以下代码来清零应用的角标数量:
```javascript
if (plus.os.name.toLowerCase() == 'ios') {
var UIApplication = plus.ios.import('UIApplication');
var app = UIApplication.sharedApplication();
plus.runtime.setBadgeNumber(0);
var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
GeTuiSdk.setBadge(0);
}
```
这段代码通过调用iOS的API来设置应用的角标数量为0。\[1\]
对于使用JPush推送服务的uniAPP应用,可以在相关的方法中设置应用的角标数量为0,例如:
```objective-c
//程序在运行时收到通知,点击通知栏进入app
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
\[UIApplication sharedApplication\].applicationIconBadgeNumber = 0;
\[JPUSHService setBadge:0\];
}
//程序在后台时收到通知,点击通知栏进入app
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
\[UIApplication sharedApplication\].applicationIconBadgeNumber = 0;
\[JPUSHService setBadge:0\];
}
//点击App图标,使App从后台恢复至前台
- (void)applicationWillEnterForeground:(UIApplication *)application {
\[application setApplicationIconBadgeNumber:0\];
\[application cancelAllLocalNotifications\];
}
//按Home键使App进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application{
\[application setApplicationIconBadgeNumber:0\];
\[application cancelAllLocalNotifications\];
}
```
这段代码通过设置应用的`applicationIconBadgeNumber`为0来清零应用的角标数量。\[2\]
另外,如果使用H5+调用push,在页面上调用消息监听时,可能会遇到消息监听事件没有被调用的情况。这可能是由于个推的SDK的问题。\[3\]在这种情况下,建议检查个推的SDK配置和使用方法是否正确,并确保消息监听事件被正确注册和调用。
#### 引用[.reference_title]
- *1* *3* [uni-app 苹果桌面icon角标清除方法](https://blog.csdn.net/Skyline_ding/article/details/103393627)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [iOS极光推送清除角标解决方案](https://blog.csdn.net/JennyHermes/article/details/78622328)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文