Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Push Notifications displayed in the Notification center

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

enter image description here

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 UILocalNotifications, and since Push Notifications aren't UILocalNotifications I have no idea what to do

Some Questions You May ask

  1. Are these notifications from my app?

    • Yes
  2. Am I using the didReceiveRemoteNotification on the AppDelegate?

    • Yes, but that's different.
  3. Does my remote notifications work/come from APNS

    • Yes.
  4. 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()
    
like image 432
Zonily Jame Avatar asked Aug 17 '17 10:08

Zonily Jame


People also ask

How do I see notifications in Notification Center?

To find your notifications, from the top of your phone screen, swipe down. Touch and hold the notification, and then tap Settings . Choose your settings: To turn off all notifications, turn off All notifications.

How do I get push notifications back?

Once you're in the Settings app, tap Notifications. In the resulting screen (Figure 1), tap Notifications. Accessing the Notification History in Android 12. In the next window (Figure 2), enable the Notification History by tapping the On/Off slider until it's in the On position.

How do I see push notifications on my iPhone?

To see your notifications in Notification Center, do any of the following: On the Lock Screen: Swipe up from the middle of the screen. On other screens: Swipe down from the top center. Then you can scroll up to see older notifications, if there are any.

Why are my push notifications not showing up on iPhone?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.


1 Answers

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)
}
like image 79
Zonily Jame Avatar answered Oct 12 '22 11:10

Zonily Jame