LuminiCode
LuminiCode

Reputation: 533

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

I would like to save all received notifications in a database.

This works if someone clicks on the notification or the notification is received while the app is in the foreground.

But the challenge is to save the notification while the app is terminated (loud push).

After the launch of the terminated app the function didFinishLaunchingWithOptions is called but the launchOptions aways is nil so I can't handle push notifications.

Does anybody have any idea to solve this problem?

Thank you in advance.

Upvotes: 3

Views: 3205

Answers (1)

LuminiCode
LuminiCode

Reputation: 533

Thanks to Goergisn.

The solution to my problem:

  1. Create an 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. Create an App Group
  3. Save data from Notification Service to App Group
  4. Create a function in the ViewController to transfer the data from the App Group into a sql-database

Upvotes: 3

Related Questions