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
How to Invoke Method with Cvalistpointer Parameters in Swift
Nsdatepicker in Nsstatusbar Nssmenuitem Not Receiving Input
Why Would One Use Nested Classes
"The Requested Snapshot Version Is Too Old." Error in Firestore
Uidatepicker Show Only Sunday's Date Only
Make Tabview Background Transparent
Windownibname Error in Swift/Cocoa
Test Enum for Equality in for ... Where Clause
How to Write to a Variable from Within The Firebase Getdocument Function (Swift)
How to Override Setter in Swift
Swiftui: Changing Default Command Menus on Macos
Avaudioconverter with Avaudioconverterinputblock Stutters Audio After Processing
How to Test If an Instance Is a Specific Class or Type in Swift
Weak Reference to Closure in Swift
Sizing a UIpickerview Inside a UIalertview
Nsmanagedobjectcontext's Propagatesdeletesatendofevent Set to False Causes Error on Save