Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 910
LuminiCode Avatar asked Dec 05 '25 18:12

LuminiCode


1 Answers

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
like image 101
LuminiCode Avatar answered Dec 08 '25 06:12

LuminiCode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!