-->

iOS 11 Prevent Screen Record like Netflix

2019-03-29 11:51发布

问题:

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?

回答1:

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


回答2:

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.



回答3:

Netflix solution is NOT about the code. It is called DRM or Digital Rights Management. It protects the data from any piracy. Including screen records/shots and downloading. Man, it's expensive.