How to delete delivered notifications from notification service extension

和自甴很熟 提交于 2020-06-28 06:13:07

问题


We are using notification service extension to display 2 types of notifications: call and cancel. The former displays message "You are being called". The second one will display "You were called".

When it comes to the latter notification, we want to remove all previously created call notifications still active in notification center. This must work when app is on background and terminated as well.

For that, we could use UNUserNotificationCenter.current().removeDeliveredNotifications.

However, within notification service extension both getDeliveredNotifications and getPendingNotificationRequests return empty list even when app has created notifications that are still displayed in notification center.

UNUserNotificationCenter.current().getPendingNotificationRequests { notifications in
    print("[NotificationService] Current pending notifications requests count: \(notifications.count)")
}

UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
    print("[NotificationService] Current notifications count: \(notifications.count)")
}

Does anyone know why such behaviour occurs? What would be alternative(s)?

来源:https://stackoverflow.com/questions/58597777/how-to-delete-delivered-notifications-from-notification-service-extension

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