--- title: "View Protection API" slug: "oapps-igios-view-protection-api-8-1-3" updated: 2026-10-20T11:53:02Z published: 2026-10-20T11:53:02Z canonical: "docs.onespan.com/oapps-igios-view-protection-api-8-1-3" excludeFromSearch: true --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.onespan.com/llms.txt > Use this file to discover all available pages before exploring further. # View Protection API The App Shielding configuration options [Block external screens](/oapps/docs/oapps-igios-configuration-options-for-ios-8-1-3#external-screens) and [Block screenshots](/oapps/docs/oapps-igios-configuration-options-for-ios-8-1-3#user-screenshots) protect the entire app from screen captures at all times. With the App Shielding SDK’s View Protection API, screen capture protection can be dynamically enabled/disabled, customized with your own colors or images, and applied to specific layers. > To avoid unwanted behavior, the `blockExternalScreens` and `blockScreenshots` config options should be disabled if any protections are enabled through the API. To use the API, you must add the ShieldSDK.xcframework bundle from the App Shielding package to your project and import the `ShieldSDK/Shield.h` header. The API enables the following protection techniques: - Hide a specific layer from screen captures - Show a specific layer during screen captures - Protect all windows with a configured overlay - Protect a specific layer with a configured overlay ## Hide and Show Layers The preferred way to use the View Protection API is to hide a given layer from screen captures and/or show a different layer. This is accomplished with the `PRMViewProtection` singleton class and the following methods: | Method | Description | | --- | --- | | `hideInScreenshots:` `showInScreenshots:` | Marks the first provided `CALayer` as being hidden/invisible in screen captures. If provided, the second `CALayer` is updated to only be visible in screen captures. The `hideInScreenshots` layer can also be `NULL` if you only want to provide a layer to show. | | `reset:` | Resets the hide/show behavior of the provided `CALayer`. | These methods must be called on the main UI thread. ### Examples The following UI Kit example hides the given label from screen captures and replaces it with a different image: ```objectivec UIImage *privacyImage = [UIImage imageNamed:@"security_overlay"]; UILabel *label = [[UILabel alloc] init]; label.text = @"Sensitive Information"; [PRMViewProtection hideInScreenshots:label.layer showInScreenshots:privacyImage.layer]; ``` The Swift equivalent looks like the following: ```swift guard let privacyImage = UIImage(named: "security_overlay") else {    return } let imageView = UIImageView(image: privacyImage) let label = UILabel() label.text = "Sensitive Information" PRMViewProtection.hideInScreenshots(label.layer, show: imageView.layer) ``` ## Custom Overlays Custom screen capture overlays can be applied to all windows or individual, specific layers. If applied to all windows, protection only takes into account windows that exist at the time the enable method is called. Any new windows created after calling the method are not automatically protected. > Custom overlays are an experimental feature and might not always work reliably. ### Configurations Configured overlays can be one of the following: - A solid color. The default configuration uses solid white if the system theme is set to light mode and solid black for dark mode. - An image. The image is scaled to cover the entire protected area. - A view. The view is added to the view hierarchy when protection is enabled. Configurations are created with the `PRMViewProtectionConfig` class, which has the following methods: | Method | Description | | --- | --- | | `defaultConfig` | Returns the default configuration as an instance of `PRMViewProtectionConfig`. | | `configWithColor:` | Creates a `PRMViewProtectionConfig` using the provided `UIColor` as the solid color overlay. | | `configWithImage:` | Creates a `PRMViewProtectionConfig` using the provided `UIImage` as the image overlay. | | `configWithView:` | Creates a `PRMViewProtectionConfig` using the provided `UIView` as the custom view overlay. | ### Protection Methods Custom protections are applied with the `PRMViewProtection` singleton class and the following methods: | Method | Description | | --- | --- | | `enableViewProtection` | Enables screen protection on all windows with the default configuration. | | `enableViewProtectionWithConfig:` | Enables screen protection on all windows using the provided `PRMViewProtectionConfig`. | | `disableViewProtection` | Removes any previously applied screen protection from all windows. This does not affect layers that were protected with `enableLayerProtection`. | | `enableLayerProtection:` | Enables screen protection only for the provided `CALayer` using the default configuration. | | `enableLayerProtection: withConfig:` | Enables screen protection only for the provided `CALayer` using the provided `PRMViewProtectionConfig`. | | `disableLayerProtection:` | Removes screen protection from the provided `CALayer`. | All methods in this class must be called on the main UI thread. It is recommended to enable view protection once when the app starts, not repeatedly in response to events like screen recording detection or view lifecycle methods. For example: ```objectivec - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    [[PRMViewProtection shared] enableViewProtection];    return YES; } ``` ### Examples The following UI Kit example applies a custom view to all windows: ```objectivec #import ... // Create configuration UIView *customOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; customOverlay.backgroundColor = [UIColor redColor]; PRMViewProtectionConfig *viewConfig = [PRMViewProtectionConfig configWithView:customOverlay]; // Enable protection [[PRMViewProtection shared] enableViewProtectionWithConfig:viewConfig]; ``` The following example applies a custom image to a specific layer: ```objectivec UIImage *warningImage = [UIImage imageNamed:@"warning_overlay"]; PRMViewProtectionConfig *imageConfig = [PRMViewProtectionConfig configWithImage:warningImage]; [[PRMViewProtection shared] enableLayerProtection:self.passwordField.layer withConfig:imageConfig]; ``` #### Swift Examples The following example is the Swift equivalent of applying a custom view to all windows: ```swift import ShieldSDK ... // Create configuration let customOverlay = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) customOverlay.backgroundColor = .red let viewConfig = PRMViewProtectionConfig.config(view: customOverlay) // Enable protection PRMViewProtection.shared().enable(with: viewConfig) ``` The following Swift example applies a custom image to a specific layer: ```swift guard let warningImage = UIImage(named: "warning_overlay") else {    return } let imageConfig = PRMViewProtectionConfig.config(image: warningImage) PRMViewProtection.shared().enableLayerProtection(passwordLayer, with: imageConfig) ```