A light weight & simple & easy camera for iOS by Swift.

Related tags

Camera DKCamera
Overview

DKCamera

Build Status Version Status license MIT Carthage compatible


Description

A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so the screen-orientation lock will be ignored(Perfect orientation handling). And it has two other purposes:

  • Can be presenting or pushing or Integrating.
  • Suppressing the warning "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates."(It seems a bug in iOS 8).
  • Compatible with iOS 11 and iPhone X

Requirements

  • Xcode 9
  • Swift 3.2 & 4.2

Installation

Swift Package Manager

In progress

SPM only support source code, which means it cannot include resources such as images.

iOS 8 and newer

DKCamera is available on CocoaPods. Simply add the following line to your podfile:

# For latest release in cocoapods
pod 'DKCamera'

iOS 7.x

Please use the 1.2.11 tag. To use Swift libraries on apps that support iOS 7, you must manually copy the files into your application project. CocoaPods only supports Swift on OS X 10.9 and newer, and iOS 8 and newer.

Easy to use

let camera = DKCamera()

camera.didCancel = {
	print("didCancel")

	self.dismiss(animated: true, completion: nil)
}

camera.didFinishCapturingImage = { (image: UIImage?, metadata: [AnyHashable : Any]?) in
    print("didFinishCapturingImage")
    
    self.dismiss(animated: true, completion: nil)
    
    self.imageView?.image = image
}

self.present(camera, animated: true, completion: nil)

You also can use these APIs:

open var cameraOverlayView: UIView?

/// The flashModel will to be remembered to next use.
open var flashMode:AVCaptureFlashMode!

open class func isAvailable() -> Bool

/// Determines whether or not the rotation is enabled.
open var allowsRotate = false

/// set to NO to hide all standard camera UI. default is YES.
open var showsCameraControls = true

open var defaultCaptureDevice = DKCameraDeviceSourceType.rear

/// Photos will be tagged with the location where they are taken.
/// Must add the "Privacy - Location XXX" tag to your Info.plist.
open var containsGPSInMetadata = false

/// Notify the listener of the detected faces in the preview frame.
open var onFaceDetection: ((_ faces: [AVMetadataFaceObject]) -> Void)?

If you are going to add a full-screen view as cameraOverlayView, maybe you should use the DKCameraPassthroughView or its subclass that have overriden the hitTest method in order to the event passes through to the expected view.

//  DKCamera.swift
public class DKCameraPassthroughView: UIView {
	public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
		let hitTestingView = super.hitTest(point, withEvent: event)
		return hitTestingView == self ? nil : hitTestingView
	}
}

License

DKCamera is released under the MIT license. See LICENSE for details.

Comments
  • Feature/swift3

    Feature/swift3

    The migration was mostly automatic - just a few lines needed manual tweaking.

    Also updated the podspec to mention it is now swift3. Bumped the version all the way up past 2.x to 3.0 - just seems like it makes sense to keep it more or less in sync with swift. Your call.

    opened by kwerle 7
  • Type 'UIView' has no member 'AnimationOptions'

    Type 'UIView' has no member 'AnimationOptions'

    I am using XCode 9.4.1 and Swift 4.1 and getting error on project compilation

    Issue Type 'UIView' has no member 'AnimationOptions'

    DKCamera.swift -> Line 793

    Solutions tried I then downgraded the pod version to 1.5.3 but it still shows the same error.

    opened by unleashedspeed 4
  • UIImage wrong orientation

    UIImage wrong orientation

    Hello. When i get an UIImage from didFinishCapturingImage it looks ok, but UIImageOrientation parameter is wrong... I use UIImage.fixOrientation() from stackoverflow to fix this. Its looks like a bad solution.. Do you know whats the reason? Thank you.

    opened by axmav 4
  • Camera screen is not in fullscreen on iPad

    Camera screen is not in fullscreen on iPad

    Hi @zhangao0086 , its great work but I'm facing an issue in camera capture. Its not opening camera view in fullscreen mode and image captured on iPad are also not in full screen. do we have any solution or workaround for that ?

    opened by Akki9326 4
  • Customcameraview and record videos

    Customcameraview and record videos

    How i can make with the DKCamera a customcameraview in the Cocoapod library are not accurately defined. The second question that i have was, can i record videos with this camera ?
    Thank you for your Help :)

    opened by Danielthenew 4
  • Possible crasher

    Possible crasher

    Our application crashed with the following backtrace:

    Thread : Crashed: com.apple.root.default-qos 0 DKCamera 0x8f4d18 DKCamera.(takePicture(DKCamera) -> () -> ()).(closure #1) (DKCamera.swift) 1 DKCamera 0x8f4be0 DKCamera.(takePicture(DKCamera) -> () -> ()).(closure #1) (DKCamera.swift:279) 2 libdispatch.dylib 0x384dced7 _dispatch_call_block_and_release + 10 3 libdispatch.dylib 0x384e8871 _dispatch_root_queue_drain + 1572 4 libdispatch.dylib 0x384e824b _dispatch_worker_thread3 + 94 5 libsystem_pthread.dylib 0x38671e29 _pthread_wqthread + 1024 6 libsystem_pthread.dylib 0x38671a18 start_wqthread + 8

    That looks like connection.videoOrientation = self.currentOrientation.toAVCaptureVideoOrientation()

    I don't understand why that could crash. Is it possible that currentOrientation or toAVCaptureVideoOrientation() could be nil?

    opened by kwerle 4
  • Rare crasher on initilization

    Rare crasher on initilization

    This happens rarely on initialization - no idea why.

    Crashed: com.apple.main-thread EXC_BREAKPOINT 0x000000010088d2d8 Thread : Crashed: com.apple.main-thread 0 DKCamera 0x10088d2d8 DKCamera.initialOriginalOrientationForOrientation() -> () (DKCamera.swift:497) 1 DKCamera 0x10089161c DKCamera.(viewWillAppear(DKCamera) -> (Bool) -> ()).(closure #1) (DKCamera.swift:113) 2 Foundation 0x1842f0334 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 16 3 Foundation 0x184243100 -[NSBlockOperation main] + 96 4 Foundation 0x184233348 -[__NSOperationInternal _start:] + 604 5 Foundation 0x1842f2728 __NSOQSchedule_f + 224 6 libdispatch.dylib 0x18339d5f0 _dispatch_client_callout + 16 7 libdispatch.dylib 0x1833a2cf8 _dispatch_main_queue_callback_4CF + 1844 8 CoreFoundation 0x183900bb0 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 12 9 CoreFoundation 0x1838fea18 __CFRunLoopRun + 1628 10 CoreFoundation 0x18382d680 CFRunLoopRunSpecific + 384 11 GraphicsServices 0x184d3c088 GSEventRunModal + 180 12 UIKit 0x1886a4d90 UIApplicationMain + 204 13 Bolt 0x10011ebc0 main (AppDelegate.swift:18) 14 libdispatch.dylib 0x1833ce8b8 (Missing)

    opened by kwerle 3
  • Overlay breaks buttons

    Overlay breaks buttons

    I've added an overlay that covers the whole screen (ios):

        cameraOverlayView = myView
        cameraOverlayView.frame = self.view.frame
    

    There are a couple of buttons on the overlay, and they work fine. But when I click on any other location on the screen, the click passes through to the focus view - bypassing the buttons (take picture, flash, reverse).

    (the buttons I'm adding on on the bottom left and on the right side of the screen)

    opened by kwerle 3
  • NSInternalInconsistencyException

    NSInternalInconsistencyException

    Hi

    The crash was produced when "take photo" button was tapped several times. Try tapping the button continually until the application will crash. If it won't, try with front-facing camera.

    In my case it was produced on several phones: iPhone 8 with iOS 12.1.2 and iPhone 5c with iOS 10.2

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (54) must be equal to the number of items contained in that section before the update (52), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

    opened by Chopyhoo 2
  • DKCamera AVCapturePhotoCaptureDelegate error

    DKCamera AVCapturePhotoCaptureDelegate error

    Hi, you have a great camera! I'm facing an issue, sometimes I catch errors while using the camera: DKCameraError: (Error: Cannot Record). It occurs randomly, I did not find any system. It occurs in class DKCameraPhotoCapturer in both functions photoOutput. Search on the Internet did not give any results of this error, what can it be? Why this error occurs? Have you any ideas?

    opened by AndrewLiashuk 2
  • Excellent library, I am using it in my iOS app

    Excellent library, I am using it in my iOS app

    I am using this library as part of my iOS app.

    previously I used ALCameraViewController. But not only was it bloated but i had alot of random app crashes. After substituting it with DKCamera my crash statistics went to 0! in version 1.5 I have not had 1 crash yet, it has been out in store for 3 days. this is my app: https://itunes.apple.com/us/app/ocr-scan-text-from-camera/id1163617952

    opened by San-Jeevan 2
  • Experience crash while capture image reported on crashlytics

    Experience crash while capture image reported on crashlytics

    Crashed: DKCamera_CaptureSession_Queue 0 DKCamera 0xe644 DKCamera.captureImage(_:) + 816 (DKCamera.swift:816) 1 DKCamera 0x12f38 partial apply for closure #1 in DKCamera.takePicture() + 721 (DKCamera.swift:721) 2 DKCamera 0x8830 thunk for @escaping @callee_guaranteed () -> () + 4338927664 (:4338927664) 3 libdispatch.dylib 0x2914 _dispatch_call_block_and_release + 32 4 libdispatch.dylib 0x4660 _dispatch_client_callout + 20 5 libdispatch.dylib 0xbde4 _dispatch_lane_serial_drain + 672 6 libdispatch.dylib 0xc958 _dispatch_lane_invoke + 392 7 libdispatch.dylib 0x171a8 _dispatch_workloop_worker_thread + 656 8 libsystem_pthread.dylib 0x10f4 _pthread_wqthread + 288 9 libsystem_pthread.dylib 0xe94 start_wqthread + 8 Screenshot 2022-01-04 at 6 36 17 PM

    opened by vinayak-nickelfox 1
  • [feature request]Catalyst support

    [feature request]Catalyst support

    Cannot override 'photoOutput' which has been marked unavailable
    
    'jpegPhotoDataRepresentation(forJPEGSampleBuffer:previewPhotoSampleBuffer:)' is unavailable in Mac Catalyst
    
    'fileDataRepresentation(withReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:)' is unavailable in Mac Catalyst
    

    image

    opened by hstdt 0
  • Crash in DKCamera.captureImage

    Crash in DKCamera.captureImage

    Recently I received this crash from app on production:

    Device

    • Model: iPhone 6
    • Orientation: Unknown
    • RAM free: 112.38 MB
    • Disk free: 41.39 MB Operating System
    • Version: 12.1.4 (16D57)
    • Orientation: Portrait
    • Jailbroken: No

    Stack trace Crashed: DKCamera_CaptureSession_Queue 0 DKCamera 0x1022c7bf4 DKCamera.captureImage(_:) + 768 (DKCamera.swift:768) 1 DKCamera 0x1022cee90 partial apply for closure #1 in DKCamera.takePicture() + 721 (DKCamera.swift:721) 2 DKCamera 0x1022bf428 thunk for @escaping @callee_guaranteed () -> () + 4326470696 (:4326470696) 3 libdispatch.dylib 0x190ac56c8 _dispatch_call_block_and_release + 24 4 libdispatch.dylib 0x190ac6484 _dispatch_client_callout + 16 5 libdispatch.dylib 0x190a6dbd0 _dispatch_lane_serial_drain$VARIANT$mp + 592 6 libdispatch.dylib 0x190a6e718 _dispatch_lane_invoke$VARIANT$mp + 432 7 libdispatch.dylib 0x190a76eb8 _dispatch_workloop_worker_thread + 600 8 libsystem_pthread.dylib 0x190ca90dc _pthread_wqthread + 312 9 libsystem_pthread.dylib 0x190cabcec start_wqthread + 4

    Any idea what can cause it or how can it be fixed? Thanks

    opened by Korshilovskiy 3
Owner
Bannings
Bannings
Library for iOS Camera API. CameraKit helps you add reliable camera to your app quickly.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

CameraKit 628 Dec 27, 2022
NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage AVFoundation or ARKit.

NextLevel 2k Jan 2, 2023
Fasttt and easy camera framework for iOS with customizable filters

FastttCamera is a wrapper around AVFoundation that allows you to build your own powerful custom camera app without all the headaches of using AVFounda

IFTTT 1.8k Dec 10, 2022
A simple, customizable camera control - video recorder for iOS.

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video recorder sc

Ömer Faruk Gül 1.2k Dec 12, 2022
Simple Swift class to provide all the configurations you need to create custom camera view in your app

Camera Manager This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientatio

Imaginary Cloud 1.3k Dec 29, 2022
BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 7, 2023
Camera engine for iOS, written in Swift, above AVFoundation. :monkey:

?? The most advanced Camera framework in Swift ?? CameraEngine is an iOS camera engine library that allows easy integration of special capture feature

Remi ROBERT 575 Dec 25, 2022
A Snapchat Inspired iOS Camera Framework written in Swift

Overview SwiftyCam is a a simple, Snapchat-style iOS Camera framework for easy photo and video capture. SwiftyCam allows users to capture both photos

Andrew Walz 2k Dec 21, 2022
A fully customisable and modern camera implementation for iOS made with AVFoundation.

Features Extremely simple and easy to use Controls autofocus & exposure Customizable interface Code-made UI assets that do not lose resolution quality

Gabriel Alvarado 1.3k Nov 30, 2022
iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing

SCRecorder A Vine/Instagram like audio/video recorder and filter framework in Objective-C. In short, here is a short list of the cool things you can d

Simon Corsin 3.1k Dec 25, 2022
An iOS framework that uses the front camera, detects your face and takes a selfie.

TakeASelfie An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front camera and draws an green oval

Abdullah Selek 37 Jan 3, 2023
Video and photo camera for iOS

Features: Description Records video ?? takes photos ?? Flash on/off ⚡ Front / Back camera ↕️ Hold to record video ✊ Tap to take photo ?? Tap to focus

André J 192 Dec 17, 2022
Instagram-like photo browser and a camera feature with a few line of code in Swift.

Fusuma is a Swift library that provides an Instagram-like photo browser with a camera feature using only a few lines of code.

Yuta Akizuki 2.4k Dec 31, 2022
A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features

Would you like to use a fully-functional camera in an iOS application in seconds? Would you like to do CoreML image recognition in just a few more sec

David Okun 868 Dec 29, 2022
ALCameraViewController - A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 6, 2022
UIView+CameraBackground - Show camera layer as a background to any UIView.

UIView+CameraBackground Show camera layer as a background to any UIView. Features Both front and back camera supported. Flash modes: auto, on, off. Co

Yonat Sharon 63 Nov 15, 2022
This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

null 0 Nov 2, 2021
Mock UIImagePickerController for testing camera based UI in simulator

Mock UIImagePickerController to simulate the camera in iOS simulator.

Yonat Sharon 18 Aug 18, 2022
ScanBarcodes is a SwiftUI view that scans barcodes using an iPhone or iPad camera.

ScanBarcodes ScanBarcodes is a SwiftUI view that scans barcodes using an iPhone or iPad camera. The framework uses AVFoundation for high performance v

NASA Jet Propulsion Laboratory 6 Nov 29, 2022