iOS development
screen capture protection
app security
mobile app development
Swift programming

How to prevent screenshots and screen recording in an iOS app

Codemia Knowledge Hub ·

You cannot fully prevent screenshots of an iOS app. Apple exposes no public API that disables screenshots for an app, unlike the secure-window flags on some other platforms. What you can do is detect some capture events, hide or blur sensitive data while the screen is being recorded or mirrored, and reduce the value of anything that does get captured.

Detecting a screenshot after it happens

You can observe that a screenshot was taken, but not block it beforehand:

swift
1import UIKit
2
3NotificationCenter.default.addObserver(
4    forName: UIApplication.userDidTakeScreenshotNotification,
5    object: nil,
6    queue: .main
7) { _ in
8    print("A screenshot was taken")
9}

This is useful for auditing or showing the user a message. Receiving the notification does not mean the capture was prevented.

Hiding content during screen recording and mirroring

For live capture such as screen recording or AirPlay mirroring, UIScreen.main.isCaptured and its change notification give a better signal:

swift
1import UIKit
2
3final class SecureViewController: UIViewController {
4    private let shieldView = UIVisualEffectView(effect: UIBlurEffect(style: .regular))
5
6    override func viewDidLoad() {
7        super.viewDidLoad()
8
9        shieldView.frame = view.bounds
10        shieldView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
11        shieldView.isHidden = true
12        view.addSubview(shieldView)
13
14        NotificationCenter.default.addObserver(
15            self,
16            selector: #selector(captureChanged),
17            name: UIScreen.capturedDidChangeNotification,
18            object: nil
19        )
20
21        updateCaptureState()
22    }
23
24    @objc private func captureChanged() {
25        updateCaptureState()
26    }
27
28    private func updateCaptureState() {
29        shieldView.isHidden = !UIScreen.main.isCaptured
30    }
31}

This does not stop every form of capture, but it hides sensitive content during active capture sessions.

Covering the app switcher snapshot

When the app moves to the background, iOS may take a snapshot for the multitasking UI. If the screen shows sensitive content, cover it before the app resigns active:

swift
1import UIKit
2
3final class PrivacyWindowController {
4    private let cover = UIView()
5
6    init(window: UIWindow) {
7        cover.frame = window.bounds
8        cover.backgroundColor = .systemBackground
9        cover.autoresizingMask = [.flexibleWidth, .flexibleHeight]
10        cover.isHidden = true
11        window.addSubview(cover)
12
13        NotificationCenter.default.addObserver(
14            self,
15            selector: #selector(hideSensitiveUI),
16            name: UIApplication.willResignActiveNotification,
17            object: nil
18        )
19
20        NotificationCenter.default.addObserver(
21            self,
22            selector: #selector(showSensitiveUI),
23            name: UIApplication.didBecomeActiveNotification,
24            object: nil
25        )
26    }
27
28    @objc private func hideSensitiveUI() { cover.isHidden = false }
29    @objc private func showSensitiveUI() { cover.isHidden = true }
30}

This is a separate leak path from user-triggered screenshots and needs its own protection.

Reducing what a capture exposes

Since you cannot guarantee prevention, limit the damage:

  • mask part of account numbers or personal data
  • require re-authentication for especially sensitive screens
  • avoid displaying secrets longer than necessary
  • watermark sensitive views if audit deterrence matters

This is usually more effective than searching for a "disable screenshot" switch that does not exist. And if the real security need is broader than screen capture, client-side UI protection alone is not enough.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design