GreedyKit is a set of ready-to-use components written in Swift for preventing sensitive media data to be exposed by screen capture tools in iOS.
I once had the task of preventing the capture of locally recorded video, however DRM did not work for me for this purpose because FairPlay only works with streaming remote content. Luckily for me, I found a suitable tool in AVFoundation, which I had to adapt to my needs and finally put into this little package.
- iOS/iPadOS 13.0 and later
- Xcode 11.0 and later
You can use Swift Package Manager to install GreedyKit using Xcode:
- Open your project in Xcode
- Open "File" -> "Add Packages..."
- Paste the repository URL: https://github.com/igooor-bb/GreedyKit
- Click "Next" a couple of times and finish adding
You can use CocoaPods to install GreedyKit
by adding following lines to your Podfile
:
target 'ApplicationName' do
pod 'GreedyKit'
end
Then just write the command in the terminal to install:
pod install
After you have installed the package, import it into the project in the usual way:
import GreedyKit
The package includes two separate but similar components for displaying images and videos that can change the capture prevention mode on demand.
To add an image in UIKit that can be hidden, you can use the GreedyImageView
wrapper around your image:
// Create image view similar to the regular UIView.
let imageView = GreedyImageView()
parentView.addSubbiew(imageView)
// Add content to the created view.
// You can use either UIImage, CGImage or CIImage.
let image = UIImage(named: "SecretImage")
imageView.setImage(image)
// When necessary, turn on the flag to prevent the content from being captured.
imageView.preventsCapture = true
To add a video in UIKit that can be hidden, you can use the GreedyPlayerView
wrapper around your AVPlayer
:
// Create a wrapper around AVPlayer
let player = AVPlayer()
let playerView = GreedyPlayerView()
playerView.player = player
// Add some content to the player and manipulate it as you wish:
let playerItem = AVPlayerItem(asset: localVideo)
player.replaceCurrentItem(with: playerItem)
player.play()
// When necessary, turn on the flag to prevent the content from being captured.
playerView.preventsCapture = true
You can find an example of how to use it in the Examples/iOSGreedyKit project.
GreedyKit also contains several wrappers around UIKit classes that you can use in SwiftUI.
The image is very simple. You just need to create a GreedyImage
element with any kind of image (UIImage, CIImage or CGImage) within your view hierarchy:
VStack {
GreedyImage(uiImage, preventsCapture: true)
}
Creating a video player is also easy. You just need to create a GreedyPlayer
element within your view hierarchy and pass an AVPlayer
to it, whose content it will draw:
VStack {
GreedyPlayer(player: avPlayer, preventsCapture: true)
}
You can find an example of how to use it in the Examples/SwiftUIGreedyKit project.
To contribute, use the follow "fork-and-pull" git workflow:
- Fork the repository on github
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a pull request so that I can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
GreedyKit is available under the MIT license. See the LICENSE file for more info.