Skip to content

An iOS camera library for photo and video capture with an easy-to-use API, flash control, camera switching, and configurable settings.

License

Notifications You must be signed in to change notification settings

nicolaischneider/SwiftCameraKit

Repository files navigation

SwiftCameraKit

Swift iOS License

SwiftCameraKit

A lightweight, easy-to-use camera library for SwiftUI and UIKit applications that handle photo or video capture (or both) with a clean API.

Features

  • Photo capture with configurable quality settings
  • Video recording with customizable settings
  • Camera switching (front/back)
  • Flash control for photos and videos
  • Camera permission handling
  • Video playback support
  • Full support for device and simulator environments

Installation

Swift Package Manager

Add SwiftCameraKit to your project via Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/yourusername/SwiftCameraKit.git", from: "1.0.0")
]

Required Permissions

Add the following keys to your Info.plist file:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access to take photos and videos</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access to record videos with audio</string>

Quick Start

Basic initialization and usage:

// Initialize camera
let cameraKit = SwiftCameraKit(view: containerView)

// Request permissions and set up camera
Task {
    let authState = await cameraKit.grantAccessForCameraAndAudio()
    if authState == .success {
        cameraKit.setupSessionAndCamera()
    }
}

// Take a photo
cameraKit.capturePhoto()

// Start/stop video recording
cameraKit.startVideoRecording()
cameraKit.stopVideoRecording()

// Switch camera and toggle flash
cameraKit.switchCamera()
cameraKit.switchFlash()

Example Projects

The package includes example integrations for both SwiftUI and UIKit:

  • SwiftUI Example: Demonstrates basic photo capture functionality.
  • SwiftUI Example: Shows more advanced features including video recording and playback.

Check the example projects for complete implementations and usage patterns.

Configuration

SwiftCameraKit can be customized with various options:

// Create custom configuration
let config = SwiftCameraKitConfig(
    photoSetting: SwiftCameraKitConfig.PhotoSettings(
        photoSessionPreset: .high,
        highQualityPhotos: true
    ),
    videoSettings: SwiftCameraKitConfig.VideoSettings(
        videoSessionPreset: .high,
        maxVideoRecordingDuration: 60,
        videoGravity: .resizeAspectFill
    )
)

// Initialize with custom config
let cameraKit = SwiftCameraKit(view: containerView, configs: config)

Requirements

  • iOS 15.0 or later
  • Swift 5.5 or later

License

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

About

An iOS camera library for photo and video capture with an easy-to-use API, flash control, camera switching, and configurable settings.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published