iOS Swift - 推送通知:将所有远程通知保存在数据库中(也在应用程序终止时)

iOS Swift - push notification: Save all Remote-Notifications in a Database (also while App is terminated)

我想将所有收到的通知保存在数据库中。

如果有人点击通知或在应用程序处于前台时收到通知,此方法有效。

但挑战是在应用程序终止时保存通知(大声推送)。

启动终止的应用程序后,函数 didFinishLaunchingWithOptions 被调用,但是 launchOptions aways 是 nil 所以我无法处理推送通知。

有人知道如何解决这个问题吗?

提前致谢。

感谢 Goergisn。

我的问题的解决方案:

  1. 创建一个 UNNotificationServiceExtension (https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications or https://medium.com/gits-apps-insight/processing-notification-data-using-notification-service-extension-6a2b5ea2da17)
  2. 创建一个应用组
  3. 将通知服务中的数据保存到应用组
  4. 在 ViewController 中创建一个函数,将数据从 App Group 传输到 sql-database