"getDeliveredNotificationsWithCompletionHandler" gives notification tray count zero : iOS12.1

669 views Asked by At

Follow below steps

  1. Open the app
  2. Lock the iPad using the lock button
  3. Then send the notification from backend-- device receives notification in the notification tray
  4. Then unlock the iPad using the lock button The app is still open since we have not pressed the Home button yet.
  5. Now when we perform "getDeliveredNotificationsWithCompletionHandler" gives notification tray count zero - it should give the count that 1 notification is received. [ IT ALSO DOES NOT GIVE ME CORRECT COUNT WHEN I PUT MY APP TO BACKGROUND AND THEN I MAKE IT FOREGROUND ]

This is the my code:

- (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];
        }

    }];
}
1

There are 1 answers

0
Suhas Arvind Patil On

This issue is in the notification payload from server side - It was like below

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

}

** But when i have made the badge value to "0" then i got the count from getDeliveredNotificationsWithCompletionHandler**

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

    }