Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

Overview

CameraKit Header

Join Spectrum Buddy.Works

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.

With CameraKit you are able to effortlessly do the following:

  • Ability to extend and create custom sessions.
  • Image and video capture seamlessly working with the same preview session.
  • Automatic system permission handling.
  • Automatic preview scaling.
  • Automatic preview/image/video output orientation handling.
  • 📷 Ability to set a custom resolution for capturing photos.
  • 📹 Ability to set resolution/frame rate for capturing videos.
  • 👱‍ Built-in face detection.
  • 📐 Built-in overlay grid.
  • 👆 Built-in tap to focus.
  • 🔍 Built-in pinch to zoom.
  • 📸 Built-in flash toggle for both photos and videos.
  • 🤳 Built-in camera position toggle.
  • 🖥 Objective-C compatible.

Sponsored By

Expensify Buddy.Works

Installation

Demo

If you want to test out the demo app first you can clone this repo to your local disk:

git clone https://github.com/CameraKit/camerakit-ios.git

and then navigate to camerakit-ios and open the CameraKit.xcworkspace file with Xcode. Near the run button select the CameraKitDemo scheme, resolve the signing conflicts using your Apple account and then run it on a real device. You cannot do much on a simulator, since we need an actual camera hardware.

Cocoapods

If you don't have Cocoapods already installed you can install it by running the code below in a terminal:

sudo gem install cocoapods

If you don't have any Podfile run:

pod init

Then open the Podfile file in your project and add this line to your app target:

pod CameraKit-iOS

and it will automatically create a Podfile and integrate the pods into the project by creating a separate .xcworkspace file. You will open this file in Xcode from now on.

Carthage

If you don't have Carthage installed run:

brew install carthage

Then create a Cartfile and add the following line:

github "CameraKit/camerakit-ios"

Code

Before adding our camera related code, make sure you include the permissions needed for your code to work in the app project Info.plist file:

<!-- Required for photos and videos -->
<key>NSCameraUsageDescription</key>
<string></string>

<!-- Optional for photos -->
<key>NSMicrophoneUsageDescription</key>
<string></string>

<!-- Optional for the demo app to copy the photos/videos to your photo library -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>

Below is a quick start code sample with session + live camera preview:

import CameraKit

...

override func viewDidLoad() {
    super.viewDidLoad()

    // Init a photo capture session
    let session = CKFPhotoSession()
    
    // Use CKFVideoSession for video capture
    // let session = CKFVideoSession()
    
    let previewView = CKFPreviewView(frame: self.view.bounds)
    previewView.session = session
}

For capturing a image using the CKFPhotoSession class use this code below:

session.capture({ (image, settings) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

If you want to record a video using the CKFVideoSession class use this code below to start the recording:

// You can also specify a custom url for where to save the video file
session.record(url: URL(string: ""), { (url) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

and end the recording:

// You can also specify a custom url for where to save the video file
session.stopRecording()

You can get the current record status via the isRecording property to determine if a recording is in progress or not.

Session properties and methods

CKFPhotoSession CKFVideoSession
zoom: Double zoom: Double
resolution: CGSize isRecording: Bool
cameraPosition: CameraPosition cameraPosition: CameraPosition
cameraDetection: CameraDetection flashMode: FlashMode
flashMode: FlashMode start()
start() stop()
stop() togglePosition()
focus(at point: CGPoint) setWidth(_ width: Int, height: Int, frameRate: Int)
togglePosition() record(url: URL? = nil, _ callback: @escaping (URL) -> Void, error: @escaping (Error) -> Void)
capture(_ callback: @escaping (UIImage, AVCaptureResolvedPhotoSettings) -> Void, _ error: @escaping (Error) -> Void) stopRecording()

Import into Objective-C projects

Go to Project Settings, Build Settings, Always Embed Swift Standard Libraries and set the value to Yes.

Then import the CameraKit framework using:

@import CameraKit;

Creating custom sessions

CameraKit can be splitted into 2 main pieces: preview and sessions. The sessions are made by extending the base CKFSession class. If you want a custom session you can extend the CKFSession class and use its static helpers to initialize yours. Or you can also extend the built-in sessions and add custom logic.

class MyCustomSession: CKFSession {

    public override init() {
        super.init()
        
        do {
            let deviceInput = try CKFSession.captureDeviceInput(type: .backCamera)
            self.session.addInput(deviceInput)
        } catch let error {
            print(error.localizedDescription)
        }
    }

    // TODO: Add your code here
}

License

CameraKit is released under the MIT License.

Comments
  • Broken preview in landscape

    Broken preview in landscape

    Is this a bug report?

    Yes

    Have you read the Contributing Guidelines?

    There is no such file

    Environment

    CameraKit Version:

    0.1

    iOS Device:

    iPhone 6S

    iOS Version:

    12.1.4

    Steps to Reproduce

    1. Include the component in your app or change the Demo app to support landscape
    2. Rotate the device to landscape

    Expected Behavior

    The preview should show what the camera sees in landscape

    Actual Behavior

    Preview showing zoomed picture rotated 90 degrees

    Reproducible Demo

    This project, the demo when allowing landscape

    Type: Bug Status: Pending 
    opened by igorkulman 3
  • Prefix collision with CloudKit framework

    Prefix collision with CloudKit framework

    Hello. Thank you for the initiative to bring this framework for all developers. :)

    I'm afraid, however, with the class name prefix you choose, that could be collisions with Apple's CloudKit framework.

    Apple suggests that ObjC "safe" prefixes use 3 letters and not only 2 (two letters prefixes would be reserved for Apple use only).

    In Swift prefixes are not usually required, so they can be removed and only specified for ObjC compatibility purposes.

    I'd suggest using something like CKF ("CameraKitFramework") as prefix while in ObjC (CKFSession, for example). And something like CameraSession, for example, while using it in Swift.

    Type: Enhancement Status: In Progress 
    opened by vmartinelli 2
  • iOS Build Error -  Unable to use  CKFPhotoSession With Objective-C

    iOS Build Error - Unable to use CKFPhotoSession With Objective-C

    Is this a bug report?

    I am testing this camerakit-ios library with Objective-C, but unfortunately i am unable to create CKFPhotoSession object it's showing compile time error on Xcode.

    Have you read the Contributing Guidelines?

    Yes

    Environment

    Xcode Version 11.3.1 (11C504)

    CameraKit Version: v1.2.1

    iOS Device: Simulator (iPhone 11 Pro Max)

    iOS Version: 13.3

    Steps to Reproduce

    (Write your steps here:)

    1. Follow installation guide for Objective-C

    2. Import CameraKit_iOS in to ViewController.h Header file

    #import <UIKit/UIKit.h>
    
    @import CameraKit_iOS;
    
    @interface ViewController : UIViewController
    
    
    @end
    
    1. Add flowing code into ViewController.m file
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        CKFPhotoSession *ckPhotoSession = [[CKFPhotoSession alloc] init];    // Error:  'init' is unavailable
    
        CKFPreviewView *ckfPreviewView = [[CKFPreviewView alloc] initWithFrame:self.view.bounds];
    
        *ckfPreviewView.session = ckPhotoSession;  // Error:  Assigning to 'CKFSession' from incompatible type 'CKFPhotoSession *__strong'
    }
    @end
    

    Expected Behavior

    CKFPhotoSession must allow to create an Objective-C object. Unfortunately it's not allow me to create any Session Object.

    Actual Behavior

    Compile tine error

    Reproducible Demo

    rahadurr/HelloCamera

    opened by rahadurr 1
  • Landscape photo always saved as portrait

    Landscape photo always saved as portrait

    Is this a bug report?

    Yes

    Have you read the Contributing Guidelines?

    No such file

    Environment

    CameraKit Version:

    0.1

    iOS Device:

    iPhone 6S

    iOS Version:

    12.1.4

    Steps to Reproduce

    (Write your steps here:)

    1. Rotate the device to landscape
    2. Take a photo
    3. Save the photo

    Expected Behavior

    Photon saved as landscape

    Actual Behavior

    Photo saved as portrait

    Reproducible Demo

    Demo in this repo

    Type: Bug Status: Pending 
    opened by igorkulman 1
  • Swift Package Manager Support (SPM SUPPORT) ADDED

    Swift Package Manager Support (SPM SUPPORT) ADDED

    Is this a bug report?

    It's not a bug that i am creating issue for.. I am adding SPM support for this CameraKit. And creating a pull request from https://github.com/dipcse07/camerakit-ios

    Have you read the Contributing Guidelines?

    Yes

    Environment

    (Please include the following information along with any other relevant environment details.)

    CameraKit Version: 1.2.1

    iOS Device:

    iOS Version:

    Steps to Reproduce

    (Write your steps here:)

    Expected Behavior

    (Write what you thought would happen.)

    Actual Behavior

    (Write what happened. Add screenshots!)

    Reproducible Demo

    (Paste the link to an example project and exact instructions to reproduce the issue.)

    (Include your CameraKit setup and usage.)

    opened by dipcse07 0
  • Release v1.2.0

    Release v1.2.0

    Release v1.2.0 of CameraKit-iOS

    • New prefix of CKF due to potential conflict with CloudKit
    • Resolved bugs related to orientation

    Close #8 Close #7 Close #10

    opened by austinkettner 0
  • How to get EXIF data from the image captured?

    How to get EXIF data from the image captured?

    Is there a way in the library to get the EXIF data from the image captured? I need the date & time the image was taken and additionally name of the image. The only thing I am getting from Exif is below:

    "{Exif}" = { PixelXDimension = 1000; PixelYDimension = 1000; };

    Full data:

    { ColorModel = RGB; Depth = 8; Orientation = 6; PixelHeight = 1000; PixelWidth = 1000; ProfileName = "Display P3"; "{Exif}" = { PixelXDimension = 1000; PixelYDimension = 1000; }; "{JFIF}" = { DensityUnit = 0; JFIFVersion = ( 1, 0, 1 ); XDensity = 72; YDensity = 72; }; "{TIFF}" = { Orientation = 6; }; }

    opened by oxnnj 0
  • Rotate photo to always portrait

    Rotate photo to always portrait

    How do I take photo always in portrait mode even if the device is in landscape or orientation lock is enabled or not all I want is to take photo in portrait mode.

    Settings I have done:

    photoSession.session.sessionPreset = .photo
            photoSession.flashMode = .auto
            
            previewView.session = self.photoSession
            previewView.autorotate = false
            previewView.previewLayer?.videoGravity = .resizeAspectFill
    

    Taken in landscape mode and device orientation is locked:

    Screen Shot 2022-06-03 at 12 51 21 PM

    Taken in landscape mode but device orientation is unlocked: Screen Shot 2022-06-03 at 12 52 02 PM

    opened by oxnnj 0
  • Using AVAudioSession for audio

    Using AVAudioSession for audio

    Need a little help, how can i add audio input device that was initiated with avAudioSession so i can record video using playAndRecord and ShareWithOthers.

    I have tried using it individually but then i have to merge audio video files which takes a lot of time and is making app slower.

    opened by RaheelAhmad123 0
  • Face detection not working correctly...

    Face detection not working correctly...

    Hello,

    I have noticed that if I start up and the back camera is on and view a face there is not face detection... then I tap more and enable face detection it does not show the face detection box, HOWEVER, if I switch camera and then switch back the face detection is on.

    So, is there a problem for the first time?

    opened by DevStreamLine 0
  • Swift Package Manager Support (SPM SUPPORT) ADDED

    Swift Package Manager Support (SPM SUPPORT) ADDED

    Is this a bug report?

    It's not a bug that i am creating issue for.. I am adding SPM support for this CameraKit. And creating a pull request from https://github.com/dipcse07/camerakit-ios Specific SPM Support repo https://github.com/dipcse07/CameraKit-SPM_Supported

    Have you read the Contributing Guidelines?

    Yes

    Environment

    (Please include the following information along with any other relevant environment details.)

    CameraKit Version: 1.2.1

    iOS Device:

    iOS Version:

    Steps to Reproduce

    (Write your steps here:)

    Expected Behavior

    (Write what you thought would happen.)

    Actual Behavior

    (Write what happened. Add screenshots!)

    Reproducible Demo

    (Paste the link to an example project and exact instructions to reproduce the issue.)

    (Include your CameraKit setup and usage.)

    opened by dipcse07 0
  • SPM SUPPORT

    SPM SUPPORT

    Proposed changes

    I used Swift Package Manager to So that everyone can use this with directly from Swift Package Manager

    Types of changes

    What types of changes does your code introduce to CameraKit? Put an x in the boxes that apply

    • [ ] Bugfix (non-breaking change which fixes an issue)
    • [ x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

    Checklist

    Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

    • [ x] I have read the CONTRIBUTING doc
    • [x ] Lint and unit tests pass locally with my changes
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] I have added necessary documentation (if appropriate)
    • [ ] Any dependent changes have been merged and published in downstream modules

    Further comments

    If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

    opened by dipcse07 0
Releases(v1.2.1)
Owner
CameraKit
CameraKit: Unified, Reliable, Camera API on Android
CameraKit
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 29, 2022
Just simple template - example how to use haptics in iOS Development

Haptics Just simple template - example how to use haptics in iOS Development imp

Alexander Ryakhin 1 Jan 31, 2022
Haptico 📳 - easy to use haptic feedback generator with pattern-play support

Haptico Haptico is easy to use iOS haptic feedback generator. Besides default haptic feedbacks it can play patterns! Checkout Example project. Table o

Sapozhnik Ivan 462 Jan 1, 2023
SwiftUI Sample Project TOUCHDOWN ECOMMERCE

SwiftUISampleProject-TOUCHDOWN-ECOMMERCE 8th day of learnign SwiftUI 4.th demo a

Mehmet Karanlık 1 Dec 24, 2021
Touchdown - SwiftUI practice project

touchdown swiftui practice project

Seth White 1 May 20, 2022
Swift library to easily check the current device and some more info about it.

Usage To run the example project, clone the repo, and run pod install from the Example directory first. let device = Deviice.current device is a Devi

Andrea Mario Lufino 56 Nov 3, 2022
Lightweight Cocoa library for detecting the running device's model and screen size.

Lightweight Cocoa library for detecting the running device's model and screen size. With the newer  devices, developers have more work to do. This li

Sebastian Dobrincu 1.3k Nov 24, 2022
Grab kbsync dynamically from your jailbroken iOS device.

KbsyncTool Grab kbsync dynamically from your jailbroken iOS device. Usage Test1:~ root# kbsynctool -s 9000 [DEBUG] Did open IPv4 listening socket 3 [D

i_82 13 Oct 31, 2022
iOS & OSX Bluetooth library for RxSwift

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Dec 16, 2022
Easily take a photo or video or choose from library

FDTake Easily take a photo or video or choose from library ?? Author's tip jar: https://amazon.com/hz/wishlist/ls/EE78A23EEGQB Usage To run the exampl

William Entriken 322 Nov 30, 2022
Super-lightweight library to detect used device

Device.swift Super-lightweight library to detect used device Device.swift extends the UIDevice class by adding a property: var deviceType: DeviceType

Johannes Schickling 219 Nov 17, 2022
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, in

EFPrefix 4.3k Jan 2, 2023
Simply the fastest way to transmit data between iOS/tvOS and OSX

DarkLightning DarkLightning is a lightweight Swift library to allow data transmission between iOS/tvOS devices (Lightning port, Dock connector, USB-C)

Jens Meder 318 Nov 29, 2022
Luminous provides you a lot of information about the system and a lot of handy methods to quickly get useful data on the iOS platform.

Luminous Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8+ Swift 5 Xcode 1

Andrea Mario Lufino 324 Nov 27, 2022
WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS.

WatchCon WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS Requirements iOS 9.0+ / watchOS 2.0+ CocoaPods CocoaPods

Abdullah Selek 33 Sep 22, 2022
Writes twitter and contact (links) to writable nfcs on iPhone 7+ iOS 14+

nfc writer ios app nfc writer app is a hacky fun side project that writes twitter and contact (links) to writable nfcs. runs on iPhone 7+ iOS 14+. joi

Vivian Phung 5 Nov 23, 2022
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
:mag_right: A simple and beautiful barcode scanner.

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 3, 2023
Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code.

Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code. CoreMotion now made insanely simple :octocat: :satellite:

Muhammad Haroon Baig 1.1k Nov 16, 2022