UNUserNotificationCenter removeAllDeliveredNotifications not working in ios 11.2

我只是一个虾纸丫 提交于 2019-11-28 03:01:39

问题


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.


回答1:


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.




回答2:


This appears to be a bug in iOS that was fixed in iOS 11.3.




回答3:


Did you try using this method:

removeDeliveredNotifications(withIdentifiers:)

You will need to pass an array of all the notification identifiers that you need to delete.



来源:https://stackoverflow.com/questions/48108165/unusernotificationcenter-removealldeliverednotifications-not-working-in-ios-11-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!