Issue in background notification iOS 18

Issue:
I am making an application that stores data locally from notifications fired from the server. Everything works fine in the foreground but the background is having problems with not being triggered when notifications are fired. So we tried firing 2 notifications at the same time, including default and silent types. But the problem continues to arise on ios 18, when firing multiple times like that, the trigger is not handling all notifications, leading to data loss. I tried on ios 15 and it worked fine.

Environment:

  • Device or Simulator: Iphone 11 pro max (iOS 18.3.2

Steps to Reproduce:

  1. Open app, allow received notification.
  2. Move app to background mode or terminate app.
  3. Sent 2 notifications:

a. Default notification payload:

{
    "aps": {
      "content-available": 1
    },
    ”notification”: {…},
    “alert”: {..},
    “data": "some_value"
  }

b. Silent notification payload:

{
    "aps": {
      "content-available": 1
    },
  ”data": "some_value"
  }

What I've Tried:

  • Trigger notification in function:
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
  • Handle write data to local storage in above function, put it in background thread also.

Thanks in advance!

Silent push notifications are not guaranteed to be delivered, and even for notifications visible to the user, background execution of the app is not guaranteed. The system decides, based on many factors, whether to execute the app in the background because it received a push notifications with "content-available": 1. In fact, terminating the app may be interpreted by the system as the user not wanting the app to be executed and might halt background execution altogether.

Therefore you should not rely on push notifications as the only way to deliver data to your app. You should instead implement a mechanism for the app to download new data whenever it seems useful (e.g. when the app starts, when the app enters the foreground etc.). Push notifications may then trigger the same mechanism for downloading new data, but nothing is lost if they don't.

If your goal is to execute some code against all push notifications, what you will want to use is a Notification Service Extension as described in the article Modifying content in newly delivered notifications

The NSE will be launched for every notification, and you can read the data from the notification and update your local data store.

Things to keep in mind,

  • your data store will need to be in a shared container so the app can later access it
  • you may want to avoid using a database or similar high memory elements in the extension as the memory and runtime are limited.
  • these notifications will have to have visible content. The extension will only run if the notification will be seen by the user, by both the notification having visible content, and the user not having turned off the visibility of your notifications.
Issue in background notification iOS 18
 
 
Q