when i open the app ,I need to read all the push notifications which are received when phone is not active or background mode. "didReceiveRemoteNotification" method call when the notification tapped only, i want to read the notification without tapping
Returns a list of the app’s notifications that are still displayed in Notification Center.
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications(completionHandler: { (notificationRequests) in
for x in notificationRequests {
print(x.request.content.body)
}
})
Here is apple doc link https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649520-getdeliverednotifications
Another way
These all remote push notification, pushed by your backend server via Apple cloud server. Better you request to your server to retrive all push notification payload in response and display to your client, Here you manage as per your need.
And then you clear notifications from notification tray.. like this.
application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With