1

Since iOS doesn't let us disable screenshoots (from what I know), I want to mask/overwrite a UIView right before the user takes a screenshoot and then remove the mask view when the screenshoot is done. I've been researching for quite a bit but still don't get any working answers. My code looks like this so far:

override func viewDidLoad() {
    super.viewDidLoad()
    
    ...

    NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: .main, using: { [weak self] _ in
        self?.addMaskView() // This adds a custom view to the top to hide all of the content in the ViewController
        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
            self?.removeMaskView() // Removes the custom view
        })
    })
}

But what this does is it added the mask view for 1 second, and hides it. But when I look at the screenshoot, it still shows the full content and not the mask view. Is there any other way to do what I want to achieve?

cleanrun
  • 549
  • 6
  • 20

1 Answers1

-1

The observer you are are working with posts the notification after the user takes screenshot thats why its not working as you intended. The most effective way is to delete the screenshot as soon as it is created via the application.

  1. As soon as the app goes to background, delete the last screenshot created

trigger a function as soon as you receive the post that the user took a screenshot, the function will override the same image with some default image from your side Also make sure the application can perform the same function while staying in background so the only way user can get scr if they instantly kill the application after getting a scr 2. You can also trigger a transparent screenoverlay that play drm protected content upon detecting screenshot. then your screenshots will be masked.

both ways are not that great but still they are only options right now

  • If the user doesn't give your app permission to access the photo library, this won't work. Also, if that is the whole reason you need to access the photo library, Apple might reject your app. The whole question is about your number 2: _how do you "DRM protect" your content so it's masked when a screenshot is taken?_ If you know how do to that, please edit your answer and add this information. – DarkDust Jul 21 '22 at 11:17
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 25 '22 at 09:30