iOS 11 Prevent Screen Record like Netflix

放肆的年华 提交于 2019-12-03 14:54:29

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

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!