MetadataScanner is a metadata scanning library built for SwiftUI apps. It provides a Button
-like view component to make scanning view easy to implement.
- iOS 14.0+
- Xcode 12.4+
- Swift 5.3+
You can use MetadataScanner
just like any other View
component inside a body: some View
property in your projects.
One thing you need to notice is that the initializer may return nil
if no available camera found. You can replace it with any placeholder view using if let else
statement (check the example), or if you don't need a placeholder you can also just ignore it, and SwiftUI will handle it as there is no view at all.
MetadataScanner(videoGravity: .resizeAspectFill,
objectTypes: [.qr],
scans: true,
onScannedObjectUpdate: { print($0) })
You may find a more real-situation example project in Example path, and it looks like below:
- Xcode > File > Swift Packages > Add Package Dependency
- Add https://github.com/el-hoshino/MetadataScanner.git
- Select "Up to Next Major" with "0.1.0"
- Create a
Package.swift
file. - Add dependencies like below:
// swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "MyAwsomeProject", dependencies: [ .package(url: "https://github.com/el-hoshino/MetadataScanner.git", from: "0.1.0") ], targets: [ .target(name: "MyAwsomeProject", dependencies: ["MetadataScanner"]) ] )