Skip to content

RanduSoft/RSQRScannerViewController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RSQRScannerViewController

A lightweight, configurable barcode and QR code scanner for iOS. Supports both UIKit and SwiftUI.

Features

  • QR codes, barcodes (EAN-8, EAN-13, Code 128, etc.), and all AVMetadataObject.ObjectType codes
  • SwiftUI CodeScannerView and UIKit RSQRScannerViewController
  • Single scan or continuous scanning mode with debounce
  • Front / back camera selection
  • Built-in torch toggle button
  • Haptic feedback on scan
  • Proper error handling with ScannerError
  • Camera permission handling
  • Privacy manifest included

Requirements

  • iOS 16.0+ / Mac Catalyst 16.0+
  • Swift 6.0+

Installation

Swift Package Manager

Add the package to your Package.swift:

dependencies: [
    .package(url: "https://github.com/RanduSoft/RSQRScannerViewController", from: "2.0.0")
]

Or in Xcode: File > Add Package Dependencies and paste the repository URL.

Setup

Add the NSCameraUsageDescription key to your Info.plist:

<key>NSCameraUsageDescription</key>
<string>We need camera access to scan codes</string>

Usage

SwiftUI

import RSQRScannerViewController

struct ScannerScreen: View {
    @State private var scannedCode: String?
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        CodeScannerView { result in
            scannedCode = result.value
            dismiss()
        }
    }
}

SwiftUI with configuration

CodeScannerView(
    configuration: ScannerConfiguration(
        codeTypes: [.qr, .ean13, .code128],
        scanMode: .continuous(),
        showTorchButton: true
    ),
    onResult: { result in
        print("Scanned \(result.codeType): \(result.value)")
    },
    onError: { error in
        print(error.localizedDescription)
    }
)

UIKit

import RSQRScannerViewController

let scanner = RSQRScannerViewController()
scanner.configuration = ScannerConfiguration(
    codeTypes: [.qr],
    hapticFeedback: true
)
scanner.onScanResult = { result in
    print(result.value)
}
scanner.onError = { error in
    print(error.localizedDescription)
}
present(scanner, animated: true)

Configuration

Property Type Default Description
codeTypes [AVMetadataObject.ObjectType] [.qr] Code types to scan
cameraPosition AVCaptureDevice.Position .back Front or back camera
scanMode ScanMode .once .once or .continuous(debounceInterval:)
hapticFeedback Bool true Vibrate on scan
showTorchButton Bool true Show flashlight button
autoDismiss Bool true Auto-dismiss after scan (.once mode)

License

RSQRScannerViewController is available under the MPL-2.0 license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages