我想将所有收到的通知保存在数据库中。
如果有人点击通知或应用程序位于前台时收到通知,则此方法有效。
但挑战是在应用程序终止时保存通知(大声推送)。
启动已终止的应用程序后,会调用函数didFinishLaunchingWithOptions,但launchOptionsaways为nil,因此我无法处理推送通知。
有人有办法解决这个问题吗?
提前谢谢您。
最佳答案
感谢 Goergisn。
我的问题的解决方案:
- 创建 UNNotificationServiceExtension( https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications 或 https://medium.com/gits-apps-insight/processing-notification-data-using-notification-service-extension-6a2b5ea2da17 )
- 创建应用组
- 将通知服务中的数据保存到应用组
- 在 ViewController 中创建一个函数,将数据从应用组传输到 sql 数据库
关于iOS Swift - 推送通知 : Save all Remote-Notifications in a Database (also while App is terminated),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64771872/