ios – Can’t get UNUserNotificationCenter.current().getDeliveredNotifications on WatchOS


PLATFORM AND VERSION

  • watchOS
  • WatchOS 10 – Watch Ultra [Simulator]
  • iPhone 15 Pro [Simulator]
  • XCode 15.0.1
  • Macbook Air M1

DESCRIPTION OF PROBLEM
I have successfully implemented the push notification on iOS and then I created a watch companion app. Notifications are bridged there too and now I want to show received notifications on my watch app. For this I called this method:

UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { (notifications) in
for notification in notifications {
//HANDLE NOTIFICATION
}
})

The problem is it always returned an empty array (Count is 0). Although notifications received for my app are present in the notification center. Then same thing has been implemented in iOS without any problem. But watch app is not returning any notification on the call of getDeliveredNotifications(completionHandler: )

Checks: I am not clearing the notifications or resetting the badge number.

The other case:

If I click the notification and open the app through the notification click, now the getDeliveredNotifications(completionHandler: ) will return that notification available in the array

STEPS TO REPRODUCE

  1. Implement the WKApplicationDelegate class
  2. On applicationDidFinishLaunching, add an observer for willEnterForegroundNotification
  3. When the observer receives the notification, call UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: )
  4. The output will be zero.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img