How to prevent screenshot and screen recording Swift apps

UISwift Team Avatar

·

·

How to Prevent screenshot

In some cases, especially for apps that handle sensitive user data, it’s important to prevent screenshots and screen recordings to enhance security. Apple provides ways to block these actions to protect confidential information.

To get started, you need to modify your app’s behavior using UIScreen and UIApplication.

Method 1: Prevent Screenshots and Screen Recording Using Secure Layer

One of the simplest ways to block screenshots and recordings is by overlaying a secure view when the app is active. This is done by setting a secure window flag in your main app window.

How it works:

• The UIApplication.userDidTakeScreenshotNotification observer detects when the user takes a screenshot and alerts them.

• A hidden black overlay (secureView) can be modified to display when needed.

Method 2: Prevent Screen Recording with isCaptured Detection

Another method is using UIScreen.main.isCaptured, which detects if the screen is being recorded.

How it works:

• UIScreen.main.isCaptured checks if screen recording is active.

• UIScreen.capturedDidChangeNotification listens for changes in the recording state.

• If recording is detected, you can log out the user, blur the screen, or display a warning.

Bonus: Apply a Privacy Screen When App Goes to Background

If your app handles sensitive data, you may also want to hide content when the app moves to the background.

How it works:

• Adds a black overlay when the app is in the background to prevent unauthorized screen peeks.

• Removes the overlay when the app returns to the foreground.

By implementing these techniques, you can enhance the security of your iOS app:

• Prevent screenshots with userDidTakeScreenshotNotification

• Detect screen recording with isCaptured

• Hide content when the app is in the background