delete certain APNs in UNNotificationServiceExtension

After receiving APNs and processing within NotificationService: UNNotificationServiceExtension, I want to delete and certain APNs. Is there any good way?

var apnsCollapseId = request.identifier
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [apnsCollapseId])
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [apnsCollapseId])

doesn't work

UNUserNotificationCenter.current().getPendingNotificationRequests { (requests: [UNNotificationRequest]) in
    UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [requests[0].identifier])
}
UNUserNotificationCenter.current().getDeliveredNotifications { (completionHandler: [UNNotification]) in
    UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [completionHandler[0].request.identifier])
}

also doesn't work. The returned completionHandler is just nil.

delete certain APNs in UNNotificationServiceExtension
 
 
Q