-2

请按照以下步骤操作

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

    }];
}
4

1 回答 1

0

此问题在服务器端的通知有效负载中 - 如下所示

{
    aps =     {
        alert =         {
            body = "";
            title = "";
        };
        badge = 1;
    };

}

** 但是,当我将徽章值设为“0”时,我从 getDeliveredNotificationsWithCompletionHandler 获得了计数**

  {
        aps =     {
            alert =         {
                body = "";
                title = "";
            };
            badge = 0;
        };

    }
于 2018-11-29T14:38:33.117 回答