Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically disabling screenshot in App

Tags:

swift

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 deleted as soon as a screenshot is taken?

let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification,
    object: nil,
    queue: mainQueue) { notification in
        // executes after screenshot
}
like image 392
Thripthi Haridas Avatar asked Jan 09 '17 09:01

Thripthi Haridas


1 Answers

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()")
    }
}
like image 76
Pushkar Raj Yadav Avatar answered Sep 30 '22 02:09

Pushkar Raj Yadav