Protecting ImageView content on iOS

Pavel Serdziukou
2 min readJan 5, 2022

--

In modern world people tend to thinking of content on the Internet as completely free and publicly available. This is a major problem in the video streaming sphere and NFT world. This leads to such phenomena as piracy, and companies want to have some kind of remedy against this behaviour.

As to mobile applications, content rights can’t be easily specified. There are such device features as screen recording and screenshots that allows users to capture any content they want in any app.

To protect text interactions on iOS there is a well-known property on the UITextField called isSecuteTextEntry. However, there is nothing to do with image and video data. At least I thought soo…

As I said, big video streaming companies always want to protect their video content from being copied. That’s why Apple introduced DRM protection feature for sample buffer layers, which are generally used to present video data from camera or remote streaming on the user interface.

It’s a really cool feature, but can we adopt it to static images?
The answer is “YES!”.

Video is just a fast changing sequence of images. If we simply place one sample buffer to this kind of layer, it will look like a plain old image view, but with an ability to protect its content.

The main problem here is converting UIImage to CMSampleBuffer instance as it requeres deep dive into Core Graphics and Core Video data manipulations. To make it easier to integrate this kind of behaviour into your projects I’ve created a small Swift package called PrivateImage.

It provides UIKit and SwiftUI variants of image views with Apple DRM protection feature. When preventCapture property is set to true, Apple automatically removes protected content from screenshots.

My wonderful dog on the left screenshot and it’s protected version on the right one

When it comes to screen recording, it can’t just start on protected view and stops, when it get presented to the screen.

Feel free to star and use it in your cool apps!

--

--