Fix: iOS Notification Banner Not Showing When App Is in Foreground

Fix: iOS Notification Banner Not Showing When App Is in Foreground

Written by

in

Quick answer: iOS suppresses native notification banners when your app is in the foreground. To show them, set UNUserNotificationCenter.current().delegate and implement userNotificationCenter(_:willPresent:withCompletionHandler:), then call completionHandler([.alert, .sound, .badge]).

Why this happens

iOS deliberately suppresses the system notification UI — banner, sound, and badge — when the target app is already frontmost. The assumption is that the app can handle the payload directly and update its own interface. This behavior dates back to the original UILocalNotification/UIRemoteNotification APIs and continues with the modern UserNotifications framework.

When a push or local notification arrives while your app is in the foreground, the system delivers the UNNotification object to your UNUserNotificationCenterDelegate instead of presenting it automatically. If you do not implement the willPresent delegate method, or if you call its completion handler with an empty option set, the notification stays silent.

Apple’s own apps (Messages, Mail, Phone) appear to bypass this restriction because they run with special entitlements and system integration. Third‑party apps must use the public delegate API introduced in iOS 10 to request the standard alert presentation.

How to fix it

1. Assign the notification center delegate early

Set the delegate in application(_:didFinishLaunchingWithOptions:) (or in your App/UIApplicationDelegate entry point) so it is ready before any notification can arrive.

import UserNotifications

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UNUserNotificationCenter.current().delegate = self
        return true
    }
}

2. Implement willPresent and request the alert

Conform to UNUserNotificationCenterDelegate and return the presentation options you want. The .alert option produces the native banner; .sound plays the notification sound; .badge increments the app icon badge.

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        // Show banner, play sound, update badge while app is frontmost
        completionHandler([.alert, .sound, .badge])
    }
}

If you only want the banner without sound or badge, pass [.alert] instead.

3. (Optional) Handle user taps on the foreground banner

When the user taps the banner, the system calls userNotificationCenter(_:didReceive:withCompletionHandler:). Use this to navigate or refresh UI.

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    // Navigate or process payload
    completionHandler()
}

4. SwiftUI app entry point (iOS 14+)

If you use the SwiftUI App protocol, attach the delegate via UIApplicationDelegateAdaptor.

import SwiftUI
import UserNotifications

class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .sound, .badge])
    }
}

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(NotificationDelegate.self) var notificationDelegate

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

How to prevent it

  • Always assign UNUserNotificationCenter.current().delegate before the first notification can fire (typically in didFinishLaunchingWithOptions or the SwiftUI App initializer).
  • Request authorization with .alert, .sound, and .badge options so the system knows you intend to present banners.
  • Test on a physical device; the simulator sometimes coalesces or delays notifications.
  • Avoid calling completionHandler([]) in willPresent unless you deliberately want to suppress the banner.

FAQ

Does this work for local notifications scheduled with UNNotificationRequest?

Yes. The same delegate method fires for both remote (APNs) and local notifications when the app is in the foreground.

Can I customize the banner appearance (colors, images, buttons)?

The stock banner uses the notification’s title, body, and app icon. For fully custom UI you must build your own in‑app view (e.g., a toast or sheet) and not call completionHandler(.alert). The native banner cannot be styled beyond the payload content.

Why does the banner still not appear after implementing the delegate?

Common causes:
– The delegate is set after a notification has already been delivered.
– Notification authorization was denied or only granted for .badge/.sound without .alert.
– A focus mode (Do Not Disturb, Sleep, etc.) is suppressing alerts system‑wide.
– The notification’s interruptionLevel is .passive and the user has disabled passive banners in Settings.

Check UNUserNotificationCenter.current().getNotificationSettings to verify the granted settings.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.