0

On both macOS and iOS, when a user takes a screenshot of a video file playing within iTunes / the TV app, the screenshot is obscured and the media player layer appears as a solid black box in the screenshot as shown here:

iOS:

ios

macOS:

macOS

I have read in other posts that it is not possible to obscure/prevent the user from taking a screenshot on iOS devices; however, as shown in these images, Apple appears to be using some method to obscure the content of the video in the screenshot file.

In these cases, how is the app managing to obscure the video content within the screenshot?

Jake Chasan
  • 6,290
  • 9
  • 44
  • 90

1 Answers1

1

For MacOS it's pretty easy... set the window level to be above a certain point, for example in one of my apps where I disallow screenshots, I do this (in Objective-C):

windowLevel = CGShieldingWindowLevel();
[myWindowOutlet setLevel: windowLevel];

For iOS it's trickier. You can tell when a screenshot has been taken, but there's no official API to stop it from happening. One person on Apple's developer forums suggested to call "touchesCancelled"

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • So just to confirm, touchesCancelled will be called before the screenshot is taken? – Jake Chasan Mar 29 '17 at 01:29
  • I don't know. It's just one possible solution I found. Give it a try and see what happens. – Michael Dautermann Mar 29 '17 at 01:31
  • And this is the only solution you know of? – Jake Chasan Mar 29 '17 at 01:32
  • There's the Snapchat method as described in [this question that I linked to](http://stackoverflow.com/questions/18680028/prevent-screen-capture-in-an-ios-app) in my answer, but it's also a little clunky. Ultimately Apple will have to change iOS to allow apps to programmatically block screenshots, and you can help make that happen by filing an enhancement request at http://bugreporter.apple.com (the more developers who ask for this feature, the more likely it will get included in iOS 11 or iOS 12). – Michael Dautermann Mar 29 '17 at 03:08
  • @MichaelDautermann I didn't get it. Maybe becaue I try it on Big Sur. When I set CGShieldingWindowLevel to my window it appears on top of everything by I can take a screenshot without problem and it's content appears on the screenshot. I am doing something wrong? – andrey.s Jun 29 '21 at 18:25