Detecting screen capturing in iOS 11

We were working on an iOS app which provide paid video content. So the possibility of getting the video being recorded using the iOS 11 screen capture feature was something that needs to be handled. Here is how I did it. NB: The code is in Objective-C as I was working on an old project. It is pretty simple and you can easily convert it to swift if you wish.

My requirement was to restrict the user from recording the video as all the videos in my app are only available for paid users. I thought of restricting the screen recording if my app was active. I couldn’t find any solution to prevent screen recording (or screenshot) for our app alone. This is an OS level feature and cannot be overriden (I couldn’t find any solution. Please do comment if you have any knowledge on this).

So, the only solution was to pause or stop the player if screen recording is happening. Luckily iOS provides a solution for this. An instance property available on UIScreen from iOS 11 called captured (isCaptured in swift). Its a Boolean value that indicates whether the contents of the screen are being cloned to another destination.

//Obj-C
@property(nonatomic, readonly, getter=isCaptured) BOOL captured;
// swift
var isCaptured: Bool { get }
I also used mirroredScreen property which detects if the screen is being mirrored by an external display.

So, the idea is to check for these bool values and stop the player if any of them are true.

I had to create a notification which will help us notify whenever this bool value turns to be true. The code is in ObjC and is pretty easy to understand. have a look at the code below.

You just have to observe the kScreenRecordingDetectorRecordingStatusChangedNotification and check if the isRecording method returns true or false.

Do check the GITHUB repo for full project.

Detecting screen capturing in iOS 11

Here is a gif for the working app.

That’s it. !

Enjoy!!

If you enjoyed reading this post, please share and give some clapps so others can find it 👏👏👏👏👏 !!!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!