Read label images
Pass PNG, JPEG, WebP or GIF label Data to scan(image:profile:). A Code 128 label encoding STOCK-4827 returns that exact string.
SwiftPM
iOS 13+ · macOS 11+
1D + 2D
MIT
Decode 1D retail, warehouse and 2D matrix labels in Swift with a static XCFramework while your app retains control of AVFoundation.
Pass PNG, JPEG, WebP or GIF label Data to scan(image:profile:). A Code 128 label encoding STOCK-4827 returns that exact string.
Pass raw RGBA pixels from AVFoundation to scanFrame(rgba:width:height:profile:) off the main thread for responsive live capture.
Decode each detection’s symbology and content.text as Swift String so leading zeros remain intact, then query your own stock API.
Add the SwiftPM repository in Xcode or Package.swift and return exact barcode strings with their symbology.
Add qrcode-barcode-scanner-swift on GitHub (listed on Swift Package Index) in Xcode or Package.swift, then link product QRCodeBarcodeScanner to your target.
SwiftPM downloads the pre-built static XCFramework (QrcodeAiScannerFFI) pinned by SHA-256 checksum, requiring no Rust toolchain and no dynamic framework embedding.
// Package.swift
dependencies: [
.package(url: "https://github.com/qrcode-ai-com/qrcode-barcode-scanner-swift.git", from: "0.12.2")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "QRCodeBarcodeScanner", package: "qrcode-barcode-scanner-swift")
]
)
]
In Xcode, use File → Add Package Dependencies with https://github.com/qrcode-ai-com/qrcode-barcode-scanner-swift.git.
XCFramework slices cover iOS 13+ (arm64), iOS Simulator 13+ (arm64, x86_64) and macOS 11+ (arm64, x86_64).
Call scan(image:profile:) inside Task.detached, parse ScanReport leniently with Codable and keep the barcode symbologies your stock workflow expects.
To test with a known reference, create a Code 128 barcode with Barcode Generator encoding STOCK-4827 and scan the exported PNG.
import Foundation
import QRCodeBarcodeScanner
struct BarcodeReading { let symbology: String; let text: String }
struct ScanReportDTO: Decodable { let detections: [DetectionDTO]; let trace: TraceDTO? }
struct DetectionDTO: Decodable { let symbology: String; let content: ContentDTO }
struct ContentDTO: Decodable { let text: String; let charset: String? }
struct TraceDTO: Decodable { let budget_exhausted: Bool? }
private let barcodeFormats: Set<String> = [
"code128", "code39", "ean13", "ean8", "upc_a", "upc_e", "itf", "data_matrix"
]
func readBarcodeImage(_ imageData: Data) async throws -> [BarcodeReading] {
try await Task.detached(priority: .userInitiated) {
let json = try scan(image: imageData, profile: "frame")
let report = try JSONDecoder().decode(ScanReportDTO.self, from: Data(json.utf8))
guard report.trace?.budget_exhausted != true else { return [] }
return report.detections
.filter { barcodeFormats.contains($0.symbology) && $0.content.charset != "unknown" }
.map { BarcodeReading(symbology: $0.symbology, text: $0.content.text) }
}.value
}
Switch from "frame" to "full" for damaged or low-contrast label photos; pass raw AVFoundation RGBA pixels to scanFrame(rgba:width:height:profile:) for live capture.
Add pdf417, aztec, code93, codabar, data_bar, data_bar_expanded, telepen or maxi_code to barcodeFormats as needed.
For a Code 128 label encoding STOCK-4827, readBarcodeImage returns BarcodeReading(symbology: "code128", text: "STOCK-4827"). A UPC-A code such as 012345678905 keeps its leading zero intact as a Swift String.
A blank image or QR-only photo returns an empty array. Invalid files or unknown options throw ScanBindingError: catch it and clear stale UI results.
Sixteen barcode formats. Decodes EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode (ISBN maps to ean13, GS1-128 to code128, ITF-14 to itf).
Static linking and Apple platforms. QrcodeAiScannerFFI links statically for iOS 13+ (arm64), iOS Simulator 13+ (arm64, x86_64) and macOS 11+ (arm64, x86_64). Keep identifiers as Swift String so leading zeros survive and query product catalogues separately.
Lenient JSON and MIT licence. Decode additive keys optionally and confirm trace.budget_exhausted is false. Current releases are MIT-licensed; see the Swift package README.
Official package documentation, ScanReport specification and licensing references.
SwiftPM, formats, leading zeros, XCFramework, AVFoundation and licensing.
It is QR Code AI’s open-source MIT-licensed Swift Package Manager library (QRCodeBarcodeScanner from qrcode-barcode-scanner-swift) bundling the shared Rust engine into a static XCFramework for decoding 16 1D and 2D barcode formats plus QR codes on iOS and macOS.
It decodes EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode, plus QR Code, Micro QR and rMQR. ISBN, GS1-128 and ITF-14 return ean13, code128 and itf.
The checksum-pinned static XCFramework bundles iOS 13+ (arm64), iOS Simulator 13+ (arm64, x86_64) and macOS 11+ (arm64, x86_64), requiring no Rust toolchain or dynamic framework signing.
No. The scanner returns each encoded identifier as a String alongside its symbology (and parsed GS1 fields when recognised), keeping leading zeros intact. Query your own product catalogue or stock backend separately.
Your app owns AVFoundation capture, camera permissions and preview UI. Convert camera sample buffers to RGBA pixels and pass them to scanFrame(rgba:width:height:profile: "frame") off the main thread.
An image with no barcode returns valid JSON with an empty detections array (confirm trace.budget_exhausted is false). Corrupt image files or unknown options throw ScanBindingError.
No. All decoding executes locally inside the linked static library on the device, with no network calls, no QR Code AI account, no API key and no creation credits.
Yes. Current releases are published under the MIT licence for commercial App Store and enterprise apps while retaining copyright and licence notices (see LICENSING.md). SDK use is separate from QR Code AI’s paid creation plans and seven-day Premium trial.