gpt4 book ai didi

ios - UNUserNotificationCenter removeAllDeliveredNotifications 在 ios 11.2 中不起作用

转载 作者:技术小花猫 更新时间:2023-10-29 10:54:19 27 4
gpt4 key购买 nike

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

提前致谢。

最佳答案

它仍在为我们工作。我刚刚在 iOS 11.2.2 上检查过它。我在 getDeliveredNotificationsWithCompletionHandler: 中使用 removeDeliveredNotificationsWithIdentifiers:,在主线程上调用 getDeliveredNotificationsWithCompletionHandler

- (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];
}];
}

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

关于ios - UNUserNotificationCenter removeAllDeliveredNotifications 在 ios 11.2 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48108165/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com