正如我在 APNS 文档中看到的那样,如果应用程序未运行,静默通知将在 didreceiveremotenotification
中处理,但它们的优先级较低。所以有时我的 iOS 应用程序收不到静默通知。
如果应用程序未运行(不在前台,不在后台),iOS 是否显示非静默通知?非静默通知是否会触发 didreceiveremotenotification
?
最佳答案
对于非静音通知,
如果应用程序处于active
或inactive
状态,将触发didreceiveremototification
。不是在 terminated
或 suspended
状态。
在 terminated
或 suspended
状态下,用户点击通知应用程序将通过调用 didFinishLaunchingWithOptions
和 launchingOptions
启动将负载作为 Dictionary
。
如果您提供UNNotificationServiceExtension
,iOS 将在收到通知时调用didReceive(_:withContentHandler:)
,您可以使用它来自定义远程通知的内容在交付给用户之前。
阅读:https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension
如果您提供UNNotificationContentExtension
,iOS 将在收到通知时调用didReceive
,您可以使用它自定义加载通知内容。
阅读:https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension
附言:
普通通知不能用作静默通知的替代/变通方法,因为您不能在应用程序终止状态下使用静默通知。
静默通知旨在将客户端应用程序与服务器上可用的更新内容同步。由于这可以在没有明确的用户交互的情况下完成,因此可以使用静默通知。
静默通知必须包含 content-available
键,并且不得包含警报、声音或角标(Badge)键。
阅读:https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
在正常通知的情况下,除非手机上的用户设置如此,否则无法隐藏通知横幅/警报/声音。
关于ios - 接入点 : Receive non silent notifications if app is not running?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46581913/