The App Shielding configuration options Block external screens and Block 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
blockExternalScreensandblockScreenshotsconfig 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 |
|---|---|
| Marks the first provided |
| Resets the hide/show behavior of the provided |
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:
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:
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 |
|---|---|
| Returns the default configuration as an instance of |
| Creates a |
| Creates a |
| Creates a |
Protection Methods
Custom protections are applied with the PRMViewProtection singleton class and the following methods:
Method | Description |
|---|---|
| Enables screen protection on all windows with the default configuration. |
| Enables screen protection on all windows using the provided |
| Removes any previously applied screen protection from all windows. This does not affect layers that were protected with |
| Enables screen protection only for the provided |
| Enables screen protection only for the provided |
| Removes screen protection from the provided |
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:
- (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:
#import <ShieldSDK/Shield.h>
...
// 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:
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:
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:
guard let warningImage = UIImage(named: "warning_overlay") else {
return
}
let imageConfig = PRMViewProtectionConfig.config(image: warningImage)
PRMViewProtection.shared().enableLayerProtection(passwordLayer, with: imageConfig)