UNUserNotificationCenter: Configuring Silent Notifications to Avoid Banner Noise
0 reputation · 09 Jul 2023, 09:50 UTC
0 reputation · 09 Jul 2023, 09:50 UTC
In iOS 10+, UNUserNotificationCenter replaces UILocalNotification and introduces categories, actions, and UNNotificationPresentationOptions for fine‑grained control over how alerts appear. Developers often use silent pushes (content‑available = 1) to wake the app in the background, but the interaction between these silent notifications and the banner/alert presentation options is not fully documented.
The goal is to keep the user experience free of unwanted visual noise while still performing background updates. However, it is unclear whether setting UNNotificationPresentationOptions.banner will suppress a banner for a silent notification, or whether the system can still display a banner under certain user settings (e.g., “Show Previews” or “Allow Alerts”). Additionally, the behavior when a silent push arrives while a visible notification is already queued remains ambiguous.
To clarify this uncertainty, I need to understand the exact conditions under which a silent notification can trigger a visible banner or alert. I also want to know if there is a reliable way to guarantee that a silent push will never produce a banner, regardless of the user’s notification preferences or the app’s current state.
Questions:
UNNotificationPresentationOptions.banner override a silent push’s lack of visual presentation, or can a banner still appear under specific notification settings?UNNotificationPresentationOptions is set to .none?32275 reputation · 09 Jul 2023, 12:49 UTC
1. Does UNNotificationPresentationOptions.banner override a silent push’s lack of visual presentation, or can a banner still appear under specific notification settings?
When a notification payload contains content‑available: 1 and no alert, sound, or badge keys, iOS treats it as a silent push. The system never considers it for visual display, so UNNotificationPresentationOptions.banner has no effect. The banner can only appear if the payload includes an alert dictionary or if the system is forced to present something (e.g., a user‑initiated local notification). In short: a truly silent push will never trigger a banner, regardless of user settings such as “Show Previews” or “Allow Alerts”.
2. Are there documented edge cases where a silent notification (content‑available = 1) will produce a visible banner or alert even when UNNotificationPresentationOptions is set to .none?
alert dictionary along with content‑available: 1, iOS treats it as a normal notification. The UNNotificationPresentationOptions you set in the delegate only affects how the system presents that alert; it does not suppress the banner if the alert is present.apns‑priority: 10 (foreground) can cause the system to treat it as a user‑visible notification even if no alert is present, because the high‑priority flag triggers immediate delivery and may prompt a banner under some rare user‑configurations. Using apns‑priority: 5 (background) is the safe choice.3. What best‑practice configuration ensures silent notifications remain truly silent across iOS 10+ while still allowing background processing?
{
"aps": {
"content-available": 1
},
"customKey": "value"
}
apns-priority: 5 to indicate background delivery.application(_:didReceiveRemoteNotification:fetchCompletionHandler:) or the UNNotificationServiceExtension, process the data quickly and call the completion handler within the 30‑second window.UNNotificationPresentationOptions.banner or any presentation options for silent pushes; they are ignored anyway.content-available is present, strip any alert, sound, or badge keys before sending.With these steps, the notification will always be silent, the system will not display a banner, and the app will be given background time to perform its update.
To tailor the recommendation to your environment, could you confirm whether the user’s Background App Refresh setting is enabled for your app? This influences whether silent pushes are delivered at all.
Use comments to ask for clarification. Post a solution as an answer.
32,275 reputation · 09 Jul 2023, 14:06 UTC
When a remote push contains only {"aps":{"content-available":1}}, iOS treats it as a silent push. The system delivers it to the app and calls application(_:didReceiveRemoteNotification:fetchCompletionHandler:) (or the equivalent background mode) even if the user has turned off Allow Notifications for the app in Settings. Because the payload lacks an alert, sound, or badge key, no UI—banner, alert, or sound—is ever shown, regardless of UNNotificationPresentationOptions or any user preview settings. This behavior makes silent pushes reliable for background work without visual noise.