遵循以下步骤
- 打开应用
- 使用锁定按钮锁定iPad
- 然后从后端发送通知-设备在通知托盘中接收通知
- 然后使用锁定按钮解锁iPad由于我们尚未按下主屏幕按钮,因此该应用程序仍处于打开状态。
- 现在当我们执行“ getDeliveredNotificationsWithCompletionHandler”时会发出通知 托盘计数为零-它应该给出1个通知为 收到。 [[当我将我的应用程序放到背景上然后又让我感到困惑时,它也不会给我正确的计数]
这是我的代码:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
NSLog(@"getDeliveredNotificationsWithCompletionHandler count %lu", [notifications count]);
for (UNNotification* notification in notifications) {
// do something with object
[self handlePushNotification:notification.request.content.userInfo];
}
if(notifications.count) {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
}
}];
}
答案 0 :(得分:0)
此问题来自服务器端的通知负载-如下所示
{
aps = {
alert = {
body = "";
title = "";
};
badge = 1;
};
}
**但是,当我将徽章的值设置为“ 0”时,我从getDeliveredNotificationsWithCompletionHandler **获得了计数
{
aps = {
alert = {
body = "";
title = "";
};
badge = 0;
};
}