iOS 10 How to view a list of pending notifications using UNUserNotificationCenter?
The getPendingNotificationRequests
call passes an array of requests to the completion closure. Try something like this:
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
print(request)
}
})
Just in case anyone needs to access notifications that are already delivered (user can see them in notification center), this can be done in the following way:
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications { notifications in
// use center.removeDeliveredNotifications(withIdentifiers:requestIdsToRemove)
// if you want to cancel some of the notifications displayed to user
}
}