ScreenProtec is a simple utility class for iOS applications that leverages UITextField's isSecureTextEntry property to prevent users from capturing screenshots. It works by overlaying a secure text field on the application's main window.
- Screenshot Prevention: Blocks screenshots by utilizing
UITextField's secure text entry feature. - Easy Integration: Minimal configuration required to activate screenshot protection.
- Version Handling: Ensures compatibility with iOS 17 and earlier versions.
Initialize a ScreenProtec instance in your SceneDelegate:
let screenProtec = ScreenProtec(window: window)Configure the protection layer:
screenProtec.configurePreventionScreenshot()Enable the screenshot prevention mechanism:
screenProtec.enabledPreventScreenshot()If you want to disable screenshot prevention:
screenProtec.disablePreventScreenshot()To add ScreenProtec to your project, you can:
- Download the source file
ScreenProtec.swiftand add it to your project. - Import the necessary
UIKitframework in your file if not already done.
Example usage in SceneDelegate.
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let screenProtec = ScreenProtec(window: window)
screenProtec.configurePreventionScreenshot()
screenProtec.enabledPreventScreenshot()
}- The solution leverages
UITextField'sisSecureTextEntryproperty, which may not be foolproof in all scenarios. - Behavior may vary depending on iOS version and system-specific security mechanisms.
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Feel free to open issues or submit pull requests if you find bugs or have suggestions for improvements and new features.