Skip to content

BottleRocketStudios/iOS-Scan

Repository files navigation

Scan

CI Status SwiftPM compatible

Scan provides a simple lightweight abstraction around AVFoundation and the iOS camera APIs. There are a few main goals:

Usage

1. Construct a CaptureSession

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)

Example

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 Targets

  • Example
    • ExampleApp.swift
      • A small SwiftUI example demonstrating potential use cases for QR and Barcode scanning

Requirements

  • iOS 14.0+
  • tvOS 14.0+
  • macOS 11+
  • Swift 5.7

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/BottleRocketStudios/iOS-Scan.git", from: "1.0.0")
]

Author

Bottle Rocket Studios

License

Scan is available under the Apache 2.0 license. See the LICENSE.txt file for more info.

Contributing

See the CONTRIBUTING document. Thank you, contributors!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages