0

everyone! I'm building an app for making documents(UIKit). And after user fill all the info, the app presents a filled document. I use UIDocumentInteractionController to present it on full screen and I would like to prevent making screenshooting of that screen. That's how I open a document

let docOpener = UIDocumentInteractionController.init(url: path)
                    docOpener.delegate = self
                   docOpener.presentPreview(animated: true)

extension PreviewVC: UIDocumentInteractionControllerDelegate {
    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self
    }
    
    func documentInteractionControllerViewForPreview(_ controller: UIDocumentInteractionController) -> UIView? {
        return self.view
     
    }
    
    func documentInteractionControllerRectForPreview(_ controller: UIDocumentInteractionController) -> CGRect {
        return self.view.frame
    }
}

I've tried to use ScreenshotPreventing-iOS framework and also this extension

  extension UIView {
    func makeSecure() {
        DispatchQueue.main.async {
            let field = UITextField()
            field.isSecureTextEntry = true
            self.addSubview(field)
            field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
            field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
            self.layer.superlayer?.addSublayer(field.layer)
            field.layer.sublayers?.first?.addSublayer(self.layer)
        }
    }

That's works, but it hides only UIView from screenshots. As I understood the UIDocumentInteractionController has no view inside and don't allow to work somehow with its layer that shows opened document. So also i've tried to put a UIView under the UIDocumentInteractionController and hide it together but it doesn't work. Please help me to hide info somehow. Thanks

  • Basically you can't. And shouldn't need to. Preventing screenshot is a myth (user can always take another device and capture the screen of the first device that way). Instead, consider what is the risk you are trying to address by preventing a screenshot? For example if information is super sensitive, make it so it's displayed only if user touches the screen or make short timeout before the information hides, etc. Linked thread discusses pretty much every option possible – timbre timbre Apr 04 '23 at 21:56
  • @klangfarb, thanks for the answer and I understand that there are another ways to get the info but there is my direct task and now there is an interesting question for me , after I spending hours and even days trying to find the answer. Isn't it really impossible ooor...? – Aliaksandr Miatnikau Apr 05 '23 at 08:29

0 Answers0