Swiftpack.co - igooor-bb/GreedyKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by igooor-bb.
igooor-bb/GreedyKit 0.2.0
Components written in Swift for preventing sensitive media data to be captured
⭐️ 19
🕓 1 year ago
iOS
.package(url: "https://github.com/igooor-bb/GreedyKit.git", from: "0.2.0")

GreedyKit

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.

Contents

Motivation

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.

Requirements

  • iOS/iPadOS 13.0 and later
  • Xcode 11.0 and later

Installation

Swift Package Manager

You can use Swift Package Manager to install GreedyKit using Xcode:

  1. Open your project in Xcode
  2. Open "File" -> "Add Packages..."
  3. Paste the repository URL: https://github.com/igooor-bb/GreedyKit
  4. Click "Next" a couple of times and finish adding

CocoaPods

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

Usage

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.

UIKit

GreedyImageView

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

GreedyPlayerView

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.

SwiftUI

GreedyKit also contains several wrappers around UIKit classes that you can use in SwiftUI.

GreedyImage

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)
}

GreedyPlayer

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.

Contribution

To contribute, use the follow "fork-and-pull" git workflow:

  1. Fork the repository on github
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. 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!

License

GreedyKit is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 19
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Release 0.2.0
1 year ago

Version 0.2.0

Commits

  • [9db22a25] Merge pull request #21 from igooor-bb/feature/1-cocoapods-support
  • [3b520911] Remove extra spaces
  • [816e4314] Update README.md
  • [836d25ef] Add CocoaPods support
  • [a78dd8e5] Merge pull request #20 from igooor-bb/feature/inline-danger
  • [2020a2b4] Revert "Dummy change in Tests"
  • [fbef6178] Dummy change in Tests
  • [f41a2cc8] Make Danger to run in inline mode
  • [6cc0262b] [norelease] Update README.md
  • [6f5442b0] Merge pull request #17 from igooor-bb/feature/2-swiftui-support
  • [0ee3b973] Fix a build with an old version of Swift
  • [17f3f6f4] Add tests to check that deinit is called
  • [30b90798] Finally fix the memory link due to CADisplayLink
  • [b7d64995] Add a SwiftUI wrapper for the GreedyPlayerView
  • [a9dffd67] Merge branch 'main' into feature/2-swiftui-support
  • [eb6c0e6e] Improve the GreedyImage initializers
  • [b2ff6c50] Merge branch 'main' into feature/2-swiftui-support

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics