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

1

2

When my app in in the foreground, it receives a push notification from my server, triggers my UNNotificationServiceExtension, and then triggers userNotificationCenter(_:willPresent:withCompletionHandler:). The notification appears at the top of the app for a couple seconds, but when I swipe the top of the phone to see the notification center, the notification isn't there.

If my phone is locked or the app is in the background while I receive the notification, then it does appear in the notification center.

How do I make the notification appear in the notification center while the app is in the foreground?

Fallacy answered 12/4, 2021 at 12:31 Comment(2)
Can you share your userNotificationCenter(_:willPresent:withCompletionHandler:) implementation?Osmious
@BurakAkkaş All I have is the single line: completionHandler([[.banner, .badge, .sound]])Fallacy
M
3

I think adding .list should do the trick

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

You can read more about UNNotificationPresentationOptions here.

Melodist answered 12/4, 2021 at 13:13 Comment(3)
Wow thank you. I knew I was missing some small detail, but I didn't see any examples using the .list field. Was stuck on this for way longer than I'd like to admit.Fallacy
As a rule of thumb I always check all the available options in an Enum before using it, saves a lot of headache later.Melodist
I would like this as well. I am using Obj C. I will keep this info handy. Thanks.Appositive

© 2022 - 2024 — McMap. All rights reserved.