kuttz / SecureYourView

Sample project demonstrate how create a view that will secure from screenshots or screen recording.
32 stars 2 forks source link

[help wanted] i want to enable/disable screenshot #1

Closed AMBE1203 closed 1 year ago

AMBE1203 commented 1 year ago

Thanks for your example project. but i want to have the following functionality, there are two buttons, clicking the first button will block screen recording, and clicking the second button will enable screen recording. Help me please!

kuttz commented 1 year ago

Yes. You can do that. I am attaching the sample code below. Anything in the YourSecureView will be secure also you can toggle the secure property of that view using the isSecure value.

class YourSecureView: UIView {

    fileprivate let secureField = UITextField()

    var isSecure: Bool = true {
        didSet {
            secureField.isSecureTextEntry = isSecure
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        commenInit()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        commenInit()
    }

    fileprivate func commenInit() {

        secureField.isSecureTextEntry = true
        self.addSubview(secureField)
        secureField.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
        secureField.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
        self.layer.superlayer?.addSublayer(secureField.layer)
        secureField.layer.sublayers?.first?.addSublayer(self.layer)
    }

}
AMBE1203 commented 1 year ago

I'm flutter and kotlin/android developer, so i don't know swift very well, can you create a project sample for me. Thank you!.

kuttz commented 1 year ago

I'm not femilier with flutter either.

AMBE1203 commented 1 year ago

can you help me create a project sample with swift or object-C and i will use it to module in my project flutter

kuttz commented 1 year ago

Sure, I will create a branch for you.

Luismi74 commented 1 year ago

I am also a flutter developer and looking into having this working on Flutter with Swift configuration.

To give you some context @kuttz, here is how our appDelegate.swift looks:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
kuttz commented 1 year ago

@AMBE1203 check the new branch attached to this issue.

AMBE1203 commented 1 year ago

it works fine, thank you very much