当应用程序在前台时,如何使远程通知出现在通知中心?

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

当我的应用程序在前台运行时,它从我的服务器接收到推送通知,触发我的 UNNotificationServiceExtension,然后触发 userNotificationCenter(_:willPresent:withCompletionHandler:)。通知会在应用程序顶部显示几秒钟,但是当我滑动 phone 顶部以查看通知中心时,通知不存在。

如果我的 phone 在我收到通知时被锁定或应用程序处于后台,那么它会出现在通知中心。

当应用程序在前台时,如何让通知出现在通知中心?

我认为添加 .list 应该可以解决问题

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

您可以阅读更多关于 UNNotificationPresentationOptions here.