UNUserNotificationCenter removeAllDeliveredNotifications在ios 11.2中不起作用

我有一个包含多个本地通知的应用。 当我尝试清除所有已发送的通知时,我称之为removeAllDeliveredNotifications方法。 它工作正常,直到ios 11.1 。 在ios 11.2及更高版本中,它不能按预期工作。 通知仍保留在通知中心。 有人可以帮我解决这个问题。

提前致谢。

它仍然在为我们工作。 我刚刚在iOS 11.2.2上查看过它。 我正在使用removeDeliveredNotificationsWithIdentifiers:removeDeliveredNotificationsWithIdentifiers:里面,在主线程上调用getDeliveredNotificationsWithCompletionHandler

 - (void)removePendingNotificationsForObjectID:(SJFObjectID *)objectID { __weak __typeof(self) weakSelf = self; [self.userNotificationCenter getDeliveredNotificationsWithCompletionHandler:^(NSArray *notifications) { __strong __typeof(weakSelf) self = weakSelf; NSMutableArray  *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]; }]; } 

虽然我在调试completionHandler时会遇到奇怪的行为。 如果暂停时间过长(无论这意味着什么),完成处理程序将无法完成(即使在继续进程执行时),导致应用程序无响应。 也许完成处理程序会被终止。

这是iOS 10.3中修复的错误。

你尝试过使用这种方法吗?

removeDeliveredNotifications(withIdentifiers:)

您需要传递一个需要删除的所有通知标识符的数组。