Privacy Shield

Apptics' privacy shield prevents the unauthorized capture of sensitive information such as financial information, personal information, private photos, and so on. Once added to the app, the privacy shield will detect the screenshots or screen recording in the app and immediately hide the sensitive content. This helps you to keep your private information, private.

Requirements

  • Applicable for apps with iOS 12+ and iPadOS 13+.

Installation 

  • Edit the podfile to install the required library for Apptics privacy shield.
Copiedsource 'https://github.com/CocoaPods/Specs.git'
	
	target '[TARGET NAME]' do
		pod 'AppticsPrivacyShield'
	end

Secure the app views

  • Wrap the app views in the Secure Views as given in the example below.
Copiedimport UIKit
import AppticsPrivacyShield

class ViewController: UIViewController {
    
// Apptics's secure views
let sImageView = APSecureImageView()
let sSecureButton = APSecureButton()
let sSecureLabel = APSecureLabel()
let sSecureTextView = APSecureTextView()
    
override func viewDidLoad() {
        super.viewDidLoad()    
		// Add to subview here.
    
		}
}

Customize the app view

  • Customize the app views as given below.
CopiedsSecureLabel.text = "Private Information"
let customLabel = sSecureLabel.label
customLabel.textColor = .white
customLabel.textAlignment = .center
customLabel.layer.cornerRadius = 10
customLabel.layer.masksToBounds = true
sSecureButton.button.setTitle("Secure Button", for: .normal)
sSecureButton.button.setTitleColor(.white, for: .normal)
sSecureButton.button.backgroundColor = .systemBlue
sSecureButton.button.layer.cornerRadius = 10

Prevent screen recording

  • Prevent screen recording using the below code.
Copiedclass SecureViewController: UIViewController {
let tableView = UITableView()
lazy var screenshotPreventView = APSecureView(contentView: tableView)

override func viewDidLoad() {
	super.viewDidLoad()
		// This is the default behavior. To disable it, please set the value to false.
		screenshotPreventView.preventScreenCapture = true

		}
}

Protect entire view

  • Protect the entire view using the below code.
Copiedclass SecureViewController: UIViewController {
let tableView = UITableView()
lazy var screenshotPreventView = APSecureView(contentView: tableView)

override func viewDidLoad() {
	super.viewDidLoad()
		// As a default behaviour, SDK will hide the view. To disable it, please set the below value to false.
		view.addSubview(screenshotPreventView)
		screenshotPreventView.isUserInteractionEnabled = true
      screenshotPreventView.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
                    screenshotPreventView.leadingAnchor.constraint(equalTo:	view.safeAreaLayoutGuide.leadingAnchor),
                    screenshotPreventView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
                    screenshotPreventView.topAnchor.constraint(equalTo: view.topAnchor),
                    screenshotPreventView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
 		 ])
	}

	// To enable or disable screen capture, recording, or sharing
 func setPreventScreenCapture(_ shouldPrevent : Bool){
   screenshotPreventView.preventScreenCapture = shouldPrevent
 }
}

Protect window from screen sharing

  • Protect the entire window from screen sharing using the below code.
Copiedoverride func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
           
	 APWindowShield.shared().enableScreenRecordingMonitoring()
}
    
override func viewDidDisappear(_ animated: Bool) {
		super.viewDidDisappear(animated)
     APWindowShield.shared().disableScreenRecordingMonitoring()

}

Customize message view

  • Customize the message view as shown in the example below.

Copiedoverride func viewDidLoad() {
 	super.viewDidLoad()
           
		// Create and configure the label
		let label = UILabel()
 		label.text = "This screen is secured"
 		label.font = UIFont.boldSystemFont(ofSize: 20)
 		label.textColor = UIColor.black
		label.translatesAutoresizingMaskIntoConstraints = false
		// Assign the label to window shield 
 		APWindowShield.shared().label = label
        
 		let imageView = UIImageView()
 		let image = UIImage(systemName: "eye.slash.fill")
 		imageView.image = image
 		imageView.contentMode = .scaleAspectFit
 		imageView.translatesAutoresizingMaskIntoConstraints = false
		// Assign the imageView to window shield 
 		APWindowShield.shared().imageView = imageView

 		// Or you could add your custom message view 
		let customView = UIView()
        
       // Create and configure the label
       let label = UILabel()
       label.text = "This screen is secured!"
       label.font = UIFont.boldSystemFont(ofSize: 20)
       label.textColor = UIColor.black
       label.translatesAutoresizingMaskIntoConstraints = false

       // Create and configure the image view
       let imageView = UIImageView()
       let image = UIImage(systemName: "eye.slash.fill")
       imageView.image = image
       imageView.contentMode = .scaleAspectFit
       imageView.translatesAutoresizingMaskIntoConstraints = false

       // Add subviews to the blur view
       customView.addSubview(label)
       customView.addSubview(imageView)

       // Define and activate layout constraints
       NSLayoutConstraint.activate([
            label.centerXAnchor.constraint(equalTo: customView.centerXAnchor),
            label.centerYAnchor.constraint(equalTo: customView.centerYAnchor, constant: -30),
            imageView.centerXAnchor.constraint(equalTo: customView.centerXAnchor),
            imageView.bottomAnchor.constraint(equalTo: label.topAnchor, constant: -10),
            imageView.widthAnchor.constraint(equalToConstant: 100),
            imageView.heightAnchor.constraint(equalToConstant: 100)
       ])
       // Assign the customview to window shield 
 		 APWindowShield.shared().contentView = customView
 		 APWindowShield.shared().enableScreenRecordingMonitoring()
}