Skip to content

ScreenShield is an iOS library that provides a simple way to protect your app's content from being captured or recorded by screenshots, screen recordings, or other screen capture methods. It works by adding a secure layer on top of your views, which prevents most screen capture mechanisms from recording the underlying content.

License

Notifications You must be signed in to change notification settings

JayantBadlani/ScreenShield

Repository files navigation

ScreenShield

ScreenShield is an iOS library that provides a simple way to protect your app's content from being captured or recorded by screenshots, screen recordings, or other screen capture methods. It works by adding a secure layer on top of your views, which prevents most screen capture mechanisms from recording the underlying content.

The library supports both UIKit and SwiftUI and can be used with ease in both. It also provides a way to start and stop listening for screen recordings, and can be customized to use different types of views

Kindly give a Star ⭐ to my repo to support my work. Thank you!

2

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CocoaPods

To install ScreenShield using CocoaPods, add the following line to your Podfile:

pod 'ScreenShield'

Then, run pod install to install the library and its dependencies.

Swift Package Manager

To install ScreenShield using Swift Package Manager, add the following line to your Package.swift:

dependencies: [
    .package(url: "https://github.com/JayantBadlani/ScreenShield", from: "1.2.2")
]

Then, run swift package update to download the library and its dependencies.

Usage

To use ScreenShield in your iOS app, simply import the library and call its methods to protect your views and listen for screen recordings.

Here's an example of how to use the library with UIKit:

import UIKit
import ScreenShield

class ViewController: UIViewController {
    
    override func viewDidAppear() {
        super.viewDidAppear()
        
        // Protect ScreenShot
        ScreenShield.shared.protect(view: self.view)
        
        // Protect Screen-Recording
        ScreenShield.shared.protectFromScreenRecording()
    }
}

And here's an example of how to use the library with SwiftUI:

import SwiftUI
import ScreenShield

struct ContentView: View {
    
    var body: some View {
        Text("Hello, World!")
            .protectScreenshot() // Protect the view
            .onAppear {
                ScreenShield.shared.protectFromScreenRecording() // Protect Screen-Recording
            }
    }
}

Integrating ScreenShield SDK with React Native

This guide explains how to integrate the ScreenShield SDK into your React Native project to protect your app from screen recording.

Installation

  1. Install the ScreenShield SDK through CocoaPods. Follow the installation instructions provided in the ScreenShield documentation.

Add this pod sdk in your podfile

    pod 'ScreenShield'

Usage

Note On all steps below, it's recommended to create files using Xcode IDE, but if you have created files from the terminal or Visual Studio Code, you need to add them to your Xcode project.

That is, you must make sure those files compiled and linked to your React Native project.

1. Add Swift File

Create/Add a Swift file with XCode named ScreenShieldRN.swift under your iOS root directory with the following content:

CreateSwiftFile-1

CreateSwiftFile-2

import Foundation
import ScreenShield

@objc(ScreenShieldRN)
class ScreenShieldRN: NSObject {

    @objc func protectScreenRecording() {
        ScreenShield.shared.protectFromScreenRecording()
    }

    @objc static func requiresMainQueueSetup() -> Bool {
        return true
    }
}

2. Add Objective-C File

Create an Objective-C file named ScreenShieldRN.m and add the following code:

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import "React/RCTLog.h"

@interface RCT_EXTERN_MODULE(ScreenShieldRN, NSObject)

RCT_EXTERN_METHOD(protectScreenRecording)

@end

3. Create a Bridge File

Create a bridge file named ScreenShieldRNBridge.h with the following code:

#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>

Usage in React Native

Now, you can use the ScreenShield functionality in your React Native code. For example:

import { NativeModules } from 'react-native';

const { ScreenShieldRN } = NativeModules;

ScreenShieldRN.protectScreenRecording(); // Call the protectScreenRecording method to protect from screen recording

That's it! With just a few lines of code, you can protect your app's content and prevent it from being recorded or captured by unwanted screen capture mechanisms.

Ensure files embedded on Xcode

  1. Right-click on your project in the Xcode project navigator and select "Add Files to [Your Project Name]":

AddFilesXcode

  1. Select the files you created in the previous steps and click "Add":

image

Note:

Preventing screen capture in an iOS app presents challenges due to the lack of direct support from the iOS operating system. In our library, we've customized our code with various hacks and workarounds to achieve the desired result. Users may encounter occasional issues with a disrupted UI. To address this, consider the following approaches for different frameworks:

For UIKit: To prevent the layout issue by incorporating "ScreenShield" protection to your view after the UI finishes loading. Implementing this protection in the viewDidAppear method can effectively mitigate layout problems.

For SwiftUI: To prevent the layout issue, add the "ScreenShield" modifier to the outermost view in the hierarchy on the screen, ensuring a secure and protected user interface experience.

⚠️ Warning Please note that the library is currently under development, and contributions are greatly appreciated.

License

ScreenShield is available under the MIT license. See the LICENSE file for more information.

Kindly give a Star ⭐ to my repo to support my work. Thank you!

About

ScreenShield is an iOS library that provides a simple way to protect your app's content from being captured or recorded by screenshots, screen recordings, or other screen capture methods. It works by adding a secure layer on top of your views, which prevents most screen capture mechanisms from recording the underlying content.

Resources

License

Stars

Watchers

Forks

Packages

No packages published