Programmatically disabling screenshot in App

前端 未结 3 534
陌清茗
陌清茗 2021-01-06 07:07

I want to prevent taking screenshot of a page in app. how to do it programmatically so that screenshots cannot be taken.

Found code to detect screenshot. Can it be

3条回答
  •  离开以前
    2021-01-06 07:49

    There is no way to prevent ScreenShots but you can prevent Screen Recording through this code.`

      func detectScreenRecording(action: @escaping () -> ()) {
            let mainQueue = OperationQueue.main
            NotificationCenter.default.addObserver(forName: UIScreen.capturedDidChangeNotification, object: nil, queue: mainQueue) { notification in
                // executes after screenshot
                action()
            }
        }
        
        
        
       //Call in vewWillApper 
         detectScreenRecording {
                print(UIScreen.main.isCaptured)
                if UIScreen.main.isCaptured{
                    //your vier hide code
                    print("self.toHide()")
                }else{
                    //  self.sceneDeleg(ate?.window?.isHidden = false
                    //your view show code
                    print("self.toShow()")
                }
            }

    `

提交回复
热议问题