A lightweight, configurable barcode and QR code scanner for iOS. Supports both UIKit and SwiftUI.
- QR codes, barcodes (EAN-8, EAN-13, Code 128, etc.), and all
AVMetadataObject.ObjectTypecodes - SwiftUI
CodeScannerViewand UIKitRSQRScannerViewController - 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
- iOS 16.0+ / Mac Catalyst 16.0+
- Swift 6.0+
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.
Add the NSCameraUsageDescription key to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need camera access to scan codes</string>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()
}
}
}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)
}
)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)| 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) |
RSQRScannerViewController is available under the MPL-2.0 license. See the LICENSE file for more info.