Giter Site home page Giter Site logo

yoxisem544 / screenshotpreventing-ios Goto Github PK

View Code? Open in Web Editor NEW
323.0 5.0 32.0 3.79 MB

Prevent screenshot or screenrecording on iOS devices

License: MIT License

Swift 94.12% Ruby 5.88%
ios screencapture screenrecord screenrecording screenshot security swift swiftpackage xcode spm

screenshotpreventing-ios's Introduction

ScreenshotPreventing

A simple wrapper view that is able to prevent screenshot or screen recording on iOS.

Requirement

iOS 12+.

SwiftUI will need iOS 13+.

Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Xcode 11+ is required to build ScreenshotPreventing using Swift Package Manager.

To integrate ScreenshotPreventing into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/yoxisem544/ScreenshotPreventing.git", .upToNextMajor(from: "1.4.0"))
]

CocoaPods

For ScreenshotPreventing, use the following entry in your Podfile:

pod 'ScreenshotPreventing', '~> 1.4.0'
# or 
pod 'ScreenshotPreventing/RxSwift', '~> 1.4.0'
# or SwiftUI
pod 'ScreenshotPreventing/SwiftUI', '~> 1.4.0'

Demo Project

Clone this project, then

cd ScreenshotPreventing
# For normal demo
open Demo/Demo.xcodeproj
# For SwiftUI demo
open Demo-SwiftUI/Demo-SwiftUI.xcodeproj

Then build for any iOS simulator to test this out.

By triggering screenshot on simulator, look for Simulator > Device > Trigger Screenshot.

Example

You can wrap view you don't want to be screenshot inside ScreenshotPreventingView

import UIKit
import ScreenshotPreventing

class ViewController: UIViewController {

    let stack = UIStackView()
    let container = ScreenshotPreventingView(contentView: stack)

    override func viewDidLoad() {
        super.viewDidLoad()

        // add to subview here.
    }
}

Or you can setup content view later.

import UIKit
import ScreenshotPreventing

class ViewController: UIViewController {

    let stack = UIStackView()
    let container = ScreenshotPreventingView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // add to subview here.
        container.setup(contentView: stack)
    }
}

SwiftUI Usage

Simply wrap your view inside ScreenshotPrevent View. You should pass in a isProtected binding to toggle on whether to prevent screenshot or not.

import SwiftUI
import ScreenshotPreventingSwiftUI

struct ContentView: View {

    @State private var preventScreenshot = false

    var body: some View {
        ScreenshotPrevent(isProtected: preventScreenshot) {
            Text("Hello")
                .padding()
                .background(Color.yellow)
                .cornerRadius(12)
        }
    }
}

or using view modifier extension

import SwiftUI
import ScreenshotPreventingSwiftUI

struct ContentView: View {

    @State private var preventScreenshot = false

    var body: some View {
        Text("Hello")
            .padding()
            .background(Color.yellow)
            .cornerRadius(12)
            .screenshotProtected(isProtected: preventScreenshot)
    }
}

RxSwift Extension

If you use RxSwift in your project, there is a Rx extension to drive preventScreenCapture property on ScreenshotPreventingView.

Use RxScreenshotPreventing package for this extension.

whetherOrNotToPreventScreenshotObservable
    .bind(to: screenshotPreventingView.rx.preventScreenCapture)
    .disposed(by: bag)

screenshotpreventing-ios's People

Contributors

yoxisem544 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

screenshotpreventing-ios's Issues

RN integration app crash upon root view invalidation

I'm trying to integrate your lib in a react native project but whenever the app reloads and the root content is invalidated the app crashes (RCTRootContentView invalidate) .

Any help is much appreciated, leaving the stack trace below:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UITextLayoutCanvasView contentViewInvalidated]: unrecognized selector sent to instance 0x7fbec9e34950'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000011220128d __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00000001106b5894 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001122163a3 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
	3   UIKitCore                           0x000000013442fd3c -[UIResponder doesNotRecognizeSelector:] + 266
	4   CoreFoundation                      0x0000000112205a20 ___forwarding___ + 1459
	5   CoreFoundation                      0x0000000112207c28 _CF_forwarding_prep_0 + 120
	6   Company                              0x00000001052d670c -[RCTRootContentView invalidate] + 124
	7   Company                              0x0000000105307675 __26-[RCTUIManager invalidate]_block_invoke + 533
	8   Company                              0x000000010531ca9a __RCTExecuteOnMainQueue_block_invoke + 26
	9   libdispatch.dylib                   0x0000000115605747 _dispatch_call_block_and_release + 12
	10  libdispatch.dylib                   0x00000001156069f7 _dispatch_client_callout + 8
	11  libdispatch.dylib                   0x0000000115616856 _dispatch_main_queue_drain + 1362
	12  libdispatch.dylib                   0x00000001156162f6 _dispatch_main_queue_callback_4CF + 31
	13  CoreFoundation                      0x000000011215d850 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	14  CoreFoundation                      0x000000011215818b __CFRunLoopRun + 2463
	15  CoreFoundation                      0x0000000112157409 CFRunLoopRunSpecific + 557
	16  GraphicsServices                    0x000000011df58187 GSEventRunModal + 137
	17  UIKitCore                           0x00000001343f83a2 -[UIApplication _run] + 972
	18  UIKitCore                           0x00000001343fce10 UIApplicationMain + 123
	19  Company                              0x0000000104c86748 main + 104
	20  dyld                                0x000000010f8023ee start_sim + 10
	21  ???                                 0x00000002070003a6 0x0 + 8707376038

Screenshot blocking not working if contentView is provided using setup(:_) method

If the contentView is not provided in init(:_) and rather lazily given using setup(contentView: UIView) method, screenshot blocking doesn't work.

The reason is preventScreenCapture variable doesn't get set in this scenario. We prematurely exit out of the setupUI() function if contentView is nil. Therefore, the below block never gets called.

DispatchQueue.main.async {
    self.preventScreenCapture = true
} 

How to work on iOS 16.4 in SwiftUI.

Hi, @yoxisem544.
Thank you for your amazing tool.

I have a few questions.
When I set your tools on iOS 16.4 in SwiftUI, I can't tap list column and my app's layout is not working well.
And I can't move to a detailed page. The preventing screenshot function is working well.

How do I fix it? Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.