iOS
notification banner
app development
foreground notifications
duplicate question

Displaying a stock iOS notification banner when your app is open and in the foreground?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Yes, you can ask iOS to show the standard notification presentation even while your app is in the foreground. The key is that foreground notifications are not shown automatically the same way background notifications are; your app must opt in by implementing the notification center delegate and returning the presentation options you want.

Use UNUserNotificationCenterDelegate

The main hook is:

swift
userNotificationCenter(_:willPresent:withCompletionHandler:)

When a notification arrives while the app is active, iOS calls this delegate method and lets your app decide how to present it.

swift
1import UIKit
2import UserNotifications
3
4@main
5class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
6    func application(
7        _ application: UIApplication,
8        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9    ) -> Bool {
10        let center = UNUserNotificationCenter.current()
11        center.delegate = self
12        center.requestAuthorization(options: [.alert, .sound, .badge]) { _, _ in }
13        return true
14    }
15
16    func userNotificationCenter(
17        _ center: UNUserNotificationCenter,
18        willPresent notification: UNNotification,
19        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
20    ) {
21        completionHandler([.banner, .sound, .list])
22    }
23}

That tells the system to use the stock foreground presentation instead of silently delivering the notification to the app with no visible banner.

If you omit those presentation options, the notification is still delivered to the app, but no standard banner is shown while the app is active.

Understand the Version-Specific Options

On newer iOS versions, .banner and .list are the standard presentation choices. In older APIs, .alert was the familiar option.

The important conceptual point is the same across versions:

  • foreground delivery happens
  • the app delegate or notification delegate decides presentation
  • the stock UI can still be used if you opt in

So if you are seeing no banner while the app is open, the likely issue is not the payload itself. It is usually that the delegate was not set or the completion handler did not request presentation.

Keep the User Experience in Mind

Just because you can show the stock banner in the foreground does not mean every notification should be shown that way. When the user is already using the app, a banner can be redundant or distracting if the same information is already visible in the current screen.

That means the best foreground policy is often selective:

  • show banners for urgent or cross-screen information
  • suppress them for content the user is already actively viewing
  • pair them with sounds or badges only when the app experience justifies it

The stock banner is available, but your app still owns the presentation decision.

That is why foreground presentation should be treated as part of notification UX design, not just as a technical checkbox.

The API makes the banner possible, but the product decision still belongs to the app.

Common Pitfalls

  • Registering notification permissions but forgetting to assign UNUserNotificationCenter.current().delegate.
  • Implementing the delegate method but not calling the completion handler with presentation options.
  • Expecting foreground notifications to show exactly like background notifications without extra code.
  • Showing banners for every in-app event and creating a noisy foreground experience.
  • Testing only the permission flow and not the separate code path that controls foreground presentation.

Summary

  • iOS can show the stock notification banner while your app is in the foreground.
  • You enable that behavior through UNUserNotificationCenterDelegate.
  • In willPresent, return presentation options such as .banner, .list, and .sound.
  • Foreground banners are opt-in, not automatic.
  • Use them deliberately so the active in-app experience stays coherent.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions