ios 11.2.1 Notifications being cleared

311 Views Asked by At

I developed an app which heavily depends on local notifications. Since upgrading to ios 11.2.1 the behavior changed without any changes in my code.

In the previous version until 11.2.0, if there were multiple notifications from the same app in notification center and one of those was answered, all other notifications remained (Unless cleaned by the code inside the app) in the notifications center.

After I upgraded to 11.2.1, every time notification is answered, all other notifications are removed as well. I tested on multiple devices in a simulator and on my iPhone 6. This also happens with other apps like Messages or Line, therefore, it is not limited to local notifications only.

Is this a bug in ios 11.2.1 or expected new behavior of notifications? In either case, is there a way to have notifications work the same way as before?

Here is a how relevant code handling answer

- (void)removeNotificationWithIdentifier:(NSString *)identifier {
    NSMutableDictionary *notifications = [self getAllNotifications];
    NSMutableDictionary *categories = [self getAllCategories];
    UNNotificationContent *content = [notifications objectForKey:identifier];
    NSString *category = [content.userInfo objectForKey:@"category"];

    [notifications removeObjectForKey:identifier];

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center removePendingNotificationRequestsWithIdentifiers:[NSArray arrayWithObjects:identifier, nil]];
    [center removeDeliveredNotificationsWithIdentifiers:[NSArray arrayWithObjects:identifier, nil]];

    if (category != nil) {
        [categories removeObjectForKey:category];
    }

    [self saveAllNotifications:notifications];
    [self saveAllCategories:categories];
}
0

There are 0 best solutions below