Skip to content

rosberry/rcam

Repository files navigation

RCam

Reusable component that presents camera flow with ability to capture image. Components presents custom UI where you can have access to all UI components of view controller.

Features

  • Camera flip
  • Flashlight mode
  • Zoom by pinch
  • Selecting focus object
  • Automatically apply orientation metadata

Usage

  1. Create and present view controller:
let cameraViewController = CameraViewController()
navigationController?.present(viewController, animated: true)
  1. Pass delegate to handle incoming image and closing event
cameraViewController.delegate = self

...

extension AppDelegate: CameraViewControllerDelegate {
    func cameraViewController(_ viewController: CameraViewController, imageCaptured image: UIImage, orientationApplied: Bool) {
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
    }

    func cameraViewControllerCloseEventTriggered(_ viewController: CameraViewController) {
        navigationController?.dismiss(animated: true)
    }
}
  1. Additions Captured image by default is raw with recorded orientation in metadata. If you need image with applied orientation, you can set automaticallyApplyOrientationToImage flag in CameraViewController to true (by default its false).

You can use CameraService separately from CameraViewController or create your own CameraService and pass it to CameraViewController constructor

let cameraViewController = CameraViewController(cameraService: YourCameraService())

Camera protocol has following interface

public protocol Camera: AnyObject {
    var captureSession: AVCaptureSession? { get }
    var videoBuffersHandler: BufferHandler? { get set }
    var audioBuffersHandler: BufferHandler? { get set }
    var recommendedAudioSettings: [AnyHashable: Any]? { get }
    var recommendedVideoSettings: [AnyHashable: Any]? { get }
    var usingBackCamera: Bool { get }
    var isTorchAvailable: Bool { get }
    var zoomLevel: CGFloat? { get set }
    var zoomRangeLimits: ClosedRange<CGFloat>? { get set }
    var availableDeviceZoomRange: ClosedRange<CGFloat>? { get }
    var flashMode: AVCaptureDevice.FlashMode { get set }
    var torchMode: AVCaptureDevice.TorchMode { get set }
    var captureMode: CaptureMode { get set }

    func videoPermissions() -> AVAuthorizationStatus
    func askVideoPermissions(completion: @escaping (Bool) -> Void)
    func microphonePermissions() -> AVAuthorizationStatus
    func askMicrophonePermissions(completion: @escaping (Bool) -> Void)

    func startSession()
    func stopSession()

    func flipCamera() throws
    func updateFocalPoint(with point: CGPoint)

    func capturePhoto(completion: @escaping PhotoHandler)
    func recordingStarted()
    func recordingFinished()
}

Installation

Depo

Depo is a universal dependency manager that combines Carthage, SPM and CocoaPods and provides common user interface to all of them.

To install RCam via Carthage using Depo you need to add this to your Depofile:

carts:
  - kind: github
    identifier: rosberry/rcam

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add the framework to your project.

github "rosberry/rcam"

SPM

Add SPM dependency to your Package.swift:

dependencies: [
    ...
    .package(url: "https://github.com/rosberry/rcam")
],
targets: [
    .target(
    ...
        dependencies: [
            ...
            .product(name: "RCam", package: "rcam")
        ]
    )
]

About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide 🌏.

Check out our open source projects, read our blog or give us a high-five on 🐦 @rosberryapps.

License

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