badge key in the aps dictionary. For client-side badge updates in the background, send a silent push with content-available: 1 (no badge key) and increment application.applicationIconBadgeNumber in didReceiveRemoteNotification:fetchCompletionHandler: when applicationState == .background. Reset the badge in applicationDidBecomeActive.Why this happens
iOS manages the app icon badge independently of your running process. When a remote notification arrives, the system—not your app—decides whether to update the badge. If the APNs payload contains a badge integer inside the aps dictionary, the SpringBoard updates the badge immediately, even when the app is suspended or terminated.
If you omit the badge key, the system does not change the badge. Your code only runs when the app is active or when a background fetch completion handler is invoked. A common misconception is that didReceiveRemoteNotification fires for every push while backgrounded; it only does so for silent pushes (those with content-available: 1) or when the user taps the notification.
Therefore, the badge appears stale until the next foreground launch because the payload either lacked the badge key or the background handler wasn’t configured to modify applicationIconBadgeNumber.
How to fix it
1. Server-side badge (simplest, most reliable)
Include the desired badge number in the APNs payload. The system applies it instantly—no code runs on the device.
Payload example
{
"aps": {
"alert": "You have 3 new messages",
"badge": 3,
"sound": "default"
}
}
Pros: Works when app is terminated, no background execution time needed, zero client code.
Cons: Your server must track the correct count per device.
2. Client-side badge update with silent push (iOS 10+)
Use this when the server cannot compute the badge (e.g., local-only data). Send a silent notification (content-available: 1, no badge key) and update the badge in the background completion handler.
Payload
{
"aps": {
"content-available": 1
}
}
AppDelegate implementation
import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
guard application.applicationState == .background else {
completionHandler(.noData)
return
}
// Compute new badge locally (example: increment)
let newBadge = application.applicationIconBadgeNumber + 1
application.applicationIconBadgeNumber = newBadge
completionHandler(.newData)
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Reset badge when user opens the app
application.applicationIconBadgeNumber = 0
}
}
Key requirements:
– Enable Background Modes → Remote notifications in Signing & Capabilities.
– The silent push must not contain a badge key; otherwise the system overwrites your change.
– Call completionHandler(.newData) (or .failed) within ~30 seconds or the system may throttle future silent pushes.
3. Hybrid approach (recommended for most apps)
Let the server set the authoritative badge via the badge key for user-visible alerts. Additionally, send a silent push without badge when background sync changes the count (e.g., message read on another device). The silent push triggers the handler above to keep the badge in sync without user interruption.
How to prevent it
- Always include
badgein theapsdictionary for user-facing notifications. - Enable Remote notifications background mode in Xcode capabilities.
- Never include a
badgekey in silent pushes intended for client-side calculation. - Reset the badge in
applicationDidBecomeActive(_:)or when the relevant data is acknowledged. - Test with the app terminated, backgrounded, and foregrounded—behavior differs.
FAQ
Why does the badge update when I tap the notification but not when I ignore it?
Tapping launches the app (or resumes it), which runs your foreground code and lets you set applicationIconBadgeNumber. Ignoring it leaves the app suspended; only the payload’s badge key or a silent-push background handler can change the badge then.
Can I use a Notification Service Extension to modify the badge?
No. A Notification Service Extension can mutate the alert payload before display, but it cannot change the app icon badge. The badge is set exclusively by the aps.badge key or by the running app process.
Does Low Power Mode block silent pushes that update the badge?
Yes. iOS may defer or drop content-available: 1 pushes when the device is in Low Power Mode. Design your server to send a visible notification with a badge key as the primary mechanism; treat silent pushes as a best-effort supplement.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
