Follow below steps
- Open the app
- Lock the iPad using the lock button
- Then send the notification from backend-- device receives notification in the notification tray
- Then unlock the iPad using the lock button The app is still open since we have not pressed the Home button yet.
- 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];
}
}];
}
This issue is in the notification payload from server side - It was like below