ios - iOS推送通知:当应用程序被快速终止或终止时如何存储推送通知有效负载?
问题描述
我正在使用 firebase 发送多个推送通知。我的应用程序收到所有通知。现在如何在应用程序被杀死或终止时将所有推送通知数据存储在用户默认值中?当应用程序被终止并且用户从所有通知中单击一个推送通知时,如何存储所有推送通知数据?
解决方案
您的应用程序不会仅通过推送通知被调用。您在通知托盘中收到的内容由 iOS 直接处理,推送通知的内容,特别是通知正文的 aps 键内的内容用于填充您在通知托盘中看到的内容。
如果应用程序处于挂起或终止状态,则不会仅仅因为您收到推送通知而调用该应用程序。当然,除非您的 apns-push-type 在您的通知中设置为背景和 content-available = 1。电话会转到
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
您可以根据应用程序要求处理内容的地方。
要检测应用程序是否从通知启动,
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
if let dict = launchingOptions?[.remoteNotification]{
//App launched from Notification
if let userInfo = dict as? [AnyHashable:Any]{
//Do what your app requires with the notification using the userInfo.
}
}
}
推荐阅读
- php - PHP 7.3 -> function_exists:神秘的“function_exists”工作
- python - Scrapy 在 Python 中使用循环
- node.js - MailGun 导致 401 禁止使用 nodeJs
- git - 当本地非常落后时,用远程来源赶上本地分支的最佳方法
- openlayers - OpenLayers 6.4.3 和 AGM (Angular Google Maps) 之间的缩放问题
- swift - 如何在 SwiftUI 中关闭 TabView?
- php - Is $_SERVER['REMOTE_ADDR'] secure?
- gatsby - 部署在 netlify 上的 Gatsby SPA 在首次加载时应用了错误的情感 css(蒸馏示例)
- cassandra - Cassandra 读取性能随时间缓慢下降
- java - 数据截断:截断不正确的 DOUBLE 值:'IntegerProperty [value: 7]'