当应用程序在前台时,如何使远程通知出现在通知中心? [英] How to make remote notification appear in notification center when app is in the foreground?
问题描述
当我的应用程序在前台时,它从我的服务器接收推送通知,触发我的UNNotificationServiceExtension
,然后触发userNotificationCenter(_:willPresent:withCompletionHandler:)
.通知会在应用顶部显示几秒钟,但当我滑动手机顶部查看通知中心时,通知不在那里.
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?
推荐答案
我认为添加 .list
应该可以解决问题
I think adding .list
should do the trick
completionHandler([.badge, .banner, .sound, .list])
您可以在此处阅读有关UNNotificationPresentationOptions
的更多信息.
You can read more about UNNotificationPresentationOptions
here.
这篇关于当应用程序在前台时,如何使远程通知出现在通知中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!