正如我在APNS文档中看到的,如果应用程序未运行,则在didreceiveremotenotification
中处理静默通知,但它们的优先级较低。因此,有时我的iOS应用程序不会收到静默通知。
如果应用程序未运行(不在前台,不在后台),iOS是否显示非静音通知?非静默通知会触发didreceiveremotenotification
吗?
对于非静默通知,
如果应用程序处于active
或inactive
状态,则会触发didreceiveremotenotification
。当处于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
p.S:
普通通知不能作为无声通知的替代/解决方案,因为您不能在应用程序终止状态下使用无声通知。
静默通知用于将客户端应用程序与服务器上可用的更新内容同步。由于这可以在没有显式用户交互的情况下完成,因此可以使用静默通知。
无声通知必须包含content-available
密钥,并且不得包含警报、声音或徽章密钥。阅读:https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
在正常通知的情况下,没有办法隐藏通知横幅/警报/声音,除非手机上的用户设置这样说