How to delete delivered notifications from notification service extension

Viewed 613

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)?

0 Answers
Related