How to Get The Push Notifications Displayed in The Notification Center

How to get the Push Notifications displayed in the Notification center

Dávid Pásztor's comment partially solved the issue because now I can retrieve the all (push and non push) Notifications displayed in the Notification Center, but only for iOS 10 because the code below is only for iOS 10 devices and above, what about other versions?

UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in
print(notifications)
}

How to make remote notification appear in notification center when app is in the foreground?

I think adding .list should do the trick

completionHandler([.badge, .banner, .sound, .list])

You can read more about UNNotificationPresentationOptions here.

Get received PUSH notification list without tap on the notification

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

Push notification doesn't appear on notification center or locked screen

Alert and sound must be in an aps object within your payload:

{
"aps":
{
"alert": "blah",
"sound": "default",
},
"myid": 12345
}

Display Push message in notification center when device is locked

It is user's settings. It can be configured in Settings App > Notification Center > ( Your APNS registered App ) > Show in Lock Screen.

In you App's programming logic, you cannot control whether it shows in Lock screen or not.



Related Topics



Leave a reply



Submit