All of these came from just one app I'm currently developing, let's call this app SampleApp
How do I get a list of these notifications from my Phone's Tray
Yes I do know that I may be able to get the notifications via this code
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in
print("here are the iOS 10 notifs \(requests)")
}
} else {
let requests = (UIApplication.shared.scheduledLocalNotifications ?? [])
print("here are the NON iOS 10 notifs \(requests)")
}
But the problem with this code is that I can only get notifications which I created offline, and not those coming from the Apple Push Notification Server (APNS)
By created offline I mean, scheduled UILocalNotification
s, and since Push Notifications aren't UILocalNotification
s I have no idea what to do
Some Questions You May ask
Are these notifications from my app?
Am I using the didReceiveRemoteNotification
on the AppDelegate
?
Does my remote notifications work/come from APNS
What does my code for registering remote notifications look like?
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: authOptions, completionHandler: { (_, _) in })
} else {
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
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)
}