AppDelegate applicationWillEnterForeground:
- (void) applicationWillEnterForeground: (UIApplication *) application {
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
NSLog(@"AppDelegate-getDeliveredNotificationsWithCompletionHandler there were %lu notifications in notification center", (unsigned long)[notifications count]);
for (UNNotification* notification in notifications) {
NSDictionary *userInfo = notification.request.content.userInfo;
if (userInfo) {
NSLog(@"Processed a notification in getDeliveredNotificationsWithCompletionHandler, with this info: %@", userInfo);
[self showPushNotificationInAlertController:userInfo];
}
}
UIApplication.sharedApplication.applicationIconBadgeNumber = 0;
}];
}}
didFinishLaunchingWithOptions: , , :
UIApplication.sharedApplication.applicationIconBadgeNumber = 0;
This currently works in iOS 12, it was not possible to test it in earlier versions. In this method, you also need to implement code for processing notifications received when the application is in the foreground: willPresentNotification: (UNNotification *) notification using CompletionHandler: and this method for processing notifications in which the user opens your application by clicking on the notification: didReceiveNotificationResponse : (UNNotificationResponse *) answer withCompletionHandler:
source
share