This article is an English version of an article I contributed to the official pamphlet of iOSDC Japan 2026 (iOS Developers Conference Japan 2026).
Introduction
Have you ever thought about what your app should do when it moves to the background? The moment a user leaves your app, iOS saves a snapshot of its screen. If that snapshot shows sensitive information, someone nearby could see it when the user casually opens the App Switcher. iOS also keeps these snapshots on the device. Regular apps can't access them, but they could potentially be extracted from a jailbroken device.
Apple's documentation states that apps should remove sensitive information when they enter the background. If you skip this step, users' personal information can be exposed without anyone meaning to. This article collects practical know-how, from choosing an approach to the implementation details, including two things that are easy to miss: the keyboard and permission alerts.
What Apple's Official Documentation Says
Apple's official documentation includes the following guideline:
Your app's UI must not contain any sensitive user information, such as passwords or credit card numbers. If your interface contains such information, remove it from your views when entering the background.
https://developer.apple.com/documentation/uikit/preparing-your-ui-to-run-in-the-background
Approach 1: privacySensitive
privacySensitive is a SwiftUI view modifier that protects the content of the view it is applied to. When the app moves to the background, the view is covered with a gray mask, as shown in Figure 1.
Text("1234 1234 1234 1234") .privacySensitive() Figure 1: Protecting a card number with privacySensitive
It takes only one line, but you have to apply it to each view you want to protect, so developers must decide which information to hide. There is also a risk of forgetting to apply it when new screens are added later.
Approach 2: A Full-Screen Overlay
The second approach covers the entire screen with a separate UIWindow whenever the app becomes inactive. Because nothing needs to be applied view by view, there is nothing to forget, and every screen in the app is protected.
Setup
To receive scene lifecycle events in a SwiftUI app, register a SceneDelegate from your AppDelegate.
// AppDelegate.swift final class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions ) -> UISceneConfiguration { let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) configuration.delegateClass = SceneDelegate.self return configuration } } // PrivacyScreenDemoApp.swift @main struct PrivacyScreenDemoApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } } Showing and Hiding the Privacy Screen
SceneDelegate.sceneWillResignActive is called just before the app becomes inactive, for example when it moves to the background or when the user opens Notification Center. Show the privacy screen here, and remove it in sceneDidBecomeActive.
// SceneDelegate.swift func sceneWillResignActive(_ scene: UIScene) { guard let windowScene = scene as? UIWindowScene else { return } if PrivacyScreenSuppression.isSuppressed { return } showPrivacyWindow(windowScene: windowScene) } func sceneDidBecomeActive(_ scene: UIScene) { hidePrivacyWindow() } showPrivacyWindow creates a new UIWindow in the same UIWindowScene, so it appears on the same screen, on top of the existing window. Its root view controller is a UIHostingController that wraps a simple SwiftUI view.
private func showPrivacyWindow(windowScene: UIWindowScene) { guard privacyWindow == nil else { return } previousFirstResponder = window?.currentFirstResponder() UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) let newWindow = UIWindow(windowScene: windowScene) newWindow.rootViewController = PrivacyScreenViewController() newWindow.isHidden = false privacyWindow = newWindow } // PrivacyScreenView.swift struct PrivacyScreenView: View { var body: some View { ZStack { Color(.systemBackground) .ignoresSafeArea() Image(systemName: "lock.shield.fill") .font(.system(size: 64)) .foregroundStyle(.secondary) } } } // PrivacyScreenViewController.swift final class PrivacyScreenViewController: UIHostingController<PrivacyScreenView> { init() { super.init(rootView: PrivacyScreenView()) } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Pitfall 1: The Keyboard
You may have noticed that showPrivacyWindow dismisses the keyboard before showing the overlay. That's because the keyboard is drawn in its own system window, which sits above your app's windows. A window you add can't cover it, so if the keyboard stays open, it remains visible on top of the privacy screen, and so does any text it shows, such as predictive suggestions.
Dismissing the keyboard alone would be inconvenient, though: when users come back, the text field they were typing in would have lost focus. So we save the current first responder before dismissing the keyboard and restore it when the privacy screen is removed. currentFirstResponder() is not a UIKit API; it is a small extension that walks the view hierarchy.
private func hidePrivacyWindow() { privacyWindow?.isHidden = true privacyWindow = nil previousFirstResponder?.becomeFirstResponder() previousFirstResponder = nil } private extension UIView { func currentFirstResponder() -> UIResponder? { if isFirstResponder { return self } for subview in subviews { if let responder = subview.currentFirstResponder() { return responder } } return nil } } Pitfall 2: Permission Alerts
System alerts, such as the camera permission dialog, also make the app inactive, so sceneWillResignActive is called. Without special handling, the screen behind the dialog switches to the privacy screen. Users then lose the context of why they are being asked for permission, which hurts their trust in the app rather than building it.
To avoid this, PrivacyScreenSuppression turns the privacy screen off only while an operation you started on purpose is running.
// PrivacyScreenSuppression.swift @MainActor enum PrivacyScreenSuppression { private(set) static var isSuppressed = false static func suppress<T>(during operation: () async throws -> T) async rethrows -> T { isSuppressed = true defer { isSuppressed = false } return try await operation() } } // The privacy screen is not shown while the permission dialog is on screen await PrivacyScreenSuppression.suppress { _ = await AVCaptureDevice.requestAccess(for: .video) } Thanks to defer, suppression ends even if the operation throws, so the app never gets stuck without protection.
How It Behaves
Whenever the app becomes inactive, the privacy screen comes to the front, so the content stays hidden in the App Switcher too. The only exception is when you intentionally present system UI, such as the camera permission dialog. When the app returns to the foreground, the privacy screen is removed automatically and focus returns to the text field the user was editing.
| Background | System alert |
|---|---|
![]() | ![]() |
Figure 2: Behavior when the app moves to the background and when the camera permission dialog is shown
Summary
Protecting information when an app moves to the background is an important part of keeping users' sensitive data safe, and it is easy to overlook. privacySensitive is easy to adopt but relies on you remembering to apply it to every sensitive view. A full-screen overlay protects the entire app uniformly, as long as you handle the keyboard and permission alerts. Choose the one that fits your app, or combine them.
The sample code from this article is available on GitHub: https://github.com/tomoakiWeb/PrivacyScreenDemo




