请按照以下步骤操作
- 打开应用程序
- 使用锁定按钮锁定 iPad
- 然后从后端发送通知——设备在通知托盘中接收通知
- 然后使用锁定按钮解锁 iPad 该应用程序仍处于打开状态,因为我们还没有按下 Home 按钮。
- 现在,当我们执行“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];
}
}];
}