[APNS][RemoteNotifications] didReceiveRemoteNotification UIBackgroundFetchResult method doesn't being called, when App is in background state, iOS swift push notification.

Hello Friends, Could you please help me, whats wrong. We have requirement that, when I receive remote notifications on device, I need to save it in to db (without tapping or opening notification banner), regardless my app is in Foreground or in Background. I receive remote notifications on device & simulator both. And UNUserNotificationCenter delegates are being called if app is in foreground, but didReceiveRemoteNotification is not calling when app is background, not killed.

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { // Save to DB completionHandler(.newData) }

I am having Xcode 15.2 & I tried on iOS versions 16.x & 17.x both on Simulator and on real devices.

// Added this code in App delegate UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in if granted { // User granted permission DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() } } else { // User denied permission } }

Replies

The behavior you are seeing is expected, and it is due to content-available (aka "background" or "silent") push notifications being throttled when being delivered to apps that are in the background.

Background push notifications are never guaranteed to be delivered to the app every single time.

Notifications sent at low priority (priority 5) are throttled, regardless of payload. As background push notifications must be sent at low priority, you may expect up to several background push notifications per hour across all apps on a device, it is entirely possible and appropriate that you may receive none at all. Delivery of a silent push to the app is at the discretion of the device.

The purpose of the throttle is to allow background activity for an app in a resource-efficient manner. It also serves to prevent apps from consuming too much of the user’s battery or cellular data with background traffic. Once the device-wide battery or data budgets have been exhausted, no more background push notifications will be delivered until the budgets are reset. The budgets and the reset schedule cannot be changed by user or developer action. Additionally, these notifications will not be delivered to the app at all if the user has not implicitly launched the app for a while.

The throttle is disabled if you run your app with a debugger attached. This allows you to test that your notifications are being received correctly, but should only be considered a best-case scenario.

The WWDC 2020 video "Background execution demystified" (https://developer.apple.com/videos/play/wwdc2020/10063/) explains the factors that effect background runtime.

If the purpose of using silent notifications is to execute some code that is triggered remotely, I suggest looking into using a Notification Service Extension as discussed at https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension. The Notification Service Extension will be executed for every visible push notification. So, it could serve your needs, as long as the user has not disabled the visibility of your notifications through various settings. The service extension will NOT be executed for push notifications that will not be presented visually.

There exists a special entitlement that will allow you to silence the visible pushes by using a Notification Service Extension. You can read more about this here: https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_usernotifications_filtering On this page you will also find a link to apply for the entitlement. This entitlement is given under limited circumstances, so we would suggest to read the requirements carefully before applying to see if you would be eligible in order to not waste time waiting for approval.

Thank you [@Gualtier Malde](https://developer.apple.com/forums/profile/Gualtier Malde) so much for responding. Actually, there is something wrong in AJO adobe test portal, it is not sending the "content-available" flag. It works using Swifty pusher tool. Thanks