Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 Prevent Screen Record like Netflix

I have video playing in my application which I don't want to be recorded. What Netflix application do is that they let the audio capture but not the video while screen is being recorded.

Anyone have idea how to implement this feature?

like image 876
Shuja Avatar asked Sep 20 '17 10:09

Shuja


3 Answers

You can listen for a UIScreenCapturedDidChange notification.

NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

This is called when iOS 11 screen recording begins and ends. When the user is recording the screen, you can modify the UI to block any content that you don't want recorded.

This notification is fired when UIScreen's isCaptured property changes. You can also inspect this property yourself:

UIScreen.main.isCaptured
like image 127
nathangitter Avatar answered Sep 19 '22 05:09

nathangitter


I believe, Netflix takes advantage of the "FairPlay Streaming" technology provided by Apple. According to Apple Documentation

If your application uses FairPlay Streaming (FPS) your video content will automatically not be captured by the iOS 11 screen recording feature or QuickTime Player on macOS. The portion of your application that is playing the content will be blacked out.

Note: FairPlay Streaming will only provide protection for the video portion of your content. To prevent capture of the audio portion you should still use the UIScreen APIs discussed in this document to provide an appropriate message to the user if screen capture begins.

One can get an in-depth understanding of FPS from the link below :

https://developer.apple.com/streaming/fps/

Any application can incorporate FPS in order to achieve same results as Netflix.

like image 31
Gurdeep Avatar answered Sep 20 '22 05:09

Gurdeep


I create a black view and add it at the top of UIWindow. Then, in view controller of PlayerVideo, create the observer

NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

Then, in screenCaptureChanged:

(void) screenCaptureChanged {
if (@available(iOS 11.0, *)) {
    BOOL isCaptured = [[UIScreen mainScreen] isCaptured];

    if (isCaptured) {
        self.blackView.hidden = false;
    }
    else {
        self.blackView.hidden = true;
    }
}

}

This solution will block the PlayerVideo when user is recording. However, I would like to create something like Netflix did. I want to let users do whatever they want while watching movie. If they are recording, they can continue watching video without black view. However, when they stop recording, the video will be save with black view. I'm still figuring out how Netflix did like this.

like image 32
vinhsteven Avatar answered Sep 19 '22 05:09

vinhsteven