[swift] hi
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import Foundation
- import UIKit
- import Flutter
- class ScreenRecordHandler: NSObject {
- private var appDelegate = (UIApplication.shared.delegate as? AppDelegate)
- weak private var screen : UIView? = nil
- static var shared = ScreenRecordHandler()
- func configure() {
- print("\(#function)")
- let controller : FlutterViewController = appDelegate?.window?.rootViewController as! FlutterViewController
- let channel = FlutterMethodChannel(name: "app.flutter.dev/ScreenRecord",
- binaryMessenger: controller.binaryMessenger)
- channel.setMethodCallHandler({
- (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
- // This method is invoked on the UI thread.
- // Handle battery messages.
- if call.method == "preventScreenRecord" {
- self.preventScreenRecord()
- } else if call.method == "preventScreenRecordDispose" {
- self.preventScreenRecordDispose()
- } else {
- result(FlutterMethodNotImplemented)
- }
- })
- }
- var field: UITextField!
- func preventScreenRecord() {
- print("preventScreenRecord")
- if let keyWindow = UIApplication.shared.keyWindow {
- hideContentOnScreenCapture(isSecure: true, window: keyWindow)
- }
- }
- func preventScreenRecordDispose() {
- print("preventScreenRecordDispose")
- if let keyWindow = UIApplication.shared.keyWindow {
- hideContentOnScreenCapture(isSecure: false, window: keyWindow)
- }
- }
- func hideContentOnScreenCapture(isSecure: Bool, window: UIWindow) {
- DispatchQueue.main.async {
- if isSecure {
- self.field = UITextField()
- self.field.isSecureTextEntry = true
- window.addSubview(self.field)
- self.field.centerYAnchor.constraint(equalTo: window.centerYAnchor).isActive = true
- self.field.centerXAnchor.constraint(equalTo: window.centerXAnchor).isActive = true
- window.layer.superlayer?.addSublayer(self.field.layer)
- self.field.layer.sublayers?.first?.addSublayer(window.layer)
- }
- else {
- if self.field != nil {
- self.field.isSecureTextEntry = false
- }
- }
- }
- }
- }
Editor
You can edit this paste and save as new: