Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNUserNotificationCenter removeAllDeliveredNotifications not working in ios 11.2

I have an app with multiple local notifications. When I try to clear all the delivered notifications, I call this removeAllDeliveredNotifications method. It's working fine till ios 11.1. In ios 11.2 and above, it doesn't work as expected. The notification still remains in the notification center. Could someone please help me out on this.

Thanks in advance.

like image 655
Sheik_101 Avatar asked Jan 05 '18 06:01

Sheik_101


Video Answer


1 Answers

It is still working for us. I just checked it on iOS 11.2.2. I am using removeDeliveredNotificationsWithIdentifiers: inside getDeliveredNotificationsWithCompletionHandler:, calling getDeliveredNotificationsWithCompletionHandler on Main Thread.

- (void)removePendingNotificationsForObjectID:(SJFObjectID *)objectID {
    __weak __typeof(self) weakSelf = self;
    [self.userNotificationCenter getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *notifications) {
        __strong __typeof(weakSelf) self = weakSelf;
        NSMutableArray <NSString *> *identifiersToRemove = [@[] mutableCopy];
        for (UNNotification *notification in notifications) {
            SJFObjectID *objectIDFromNotification = [self.notificationToObjectIDMarshaller marshalNotification:notification];
            if ([objectID isEqual:objectIDFromNotification]) {
                [identifiersToRemove addObject:notification.request.identifier];
            }
        }
        [self.userNotificationCenter removeDeliveredNotificationsWithIdentifiers:identifiersToRemove];
    }];
}

Though I experience strange behavior if I am debugging the completionHandler. If a pause too long (whatever that means) the completion handler will not finish (even on continue process execution) resulting in an unresponsive app. Maybe the completionhandler gets terminated.

like image 70
cornr Avatar answered Oct 14 '22 14:10

cornr