Scan provides a simple lightweight abstraction around AVFoundation and the iOS camera APIs. There are a few main goals:
The MetadataCaptureSession
is the main object that will be interfaced with when scanning for QR and various types of bar codes. Once started, the MetadataCaptureSession
will report back any detected objects through it's outputStream
property. This stream can be immediately iterated over after initialization using a Task
in the simplest of cases. For example:
self.metadataCaptureSession = try .defaultVideo(capturing: metadataObjectTypes, previewVideoGravity: .resizeAspectFill)
Task {
for await metadataObject in metadataCaptureSession.outputStream {
if let readableObject = metadataObject as? MachineReadableMetadataObject {
// Handle recognized object
}
}
}
There are various configuration options available on the MetadataCaptureSession
and it's properties, intended to mirror the configuration available in the AVFoundation
types they are based on. One key configuration option is the rectOfInterest
. This can be updated using the below sample code. Note that the CGRect
passed in here requires no manual transformations, it is given in the view
coordinate space.
metadataCaptureSession.setViewRectOfInterest(newRectOfInterest)
Clone the repo:
git clone https://github.com/BottleRocketStudios/iOS-Scan.git
From here, you can open up Scan.xcworkspace
and run the examples:
- Example
ExampleApp.swift
- A small SwiftUI example demonstrating potential use cases for QR and Barcode scanning
- iOS 14.0+
- tvOS 14.0+
- macOS 11+
- Swift 5.7
dependencies: [
.package(url: "https://github.com/BottleRocketStudios/iOS-Scan.git", from: "1.0.0")
]
Scan is available under the Apache 2.0 license. See the LICENSE.txt file for more info.
See the CONTRIBUTING document. Thank you, contributors!