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 full control over 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 smooth live capture.
Decode each detection’s symbology and content.text as Swift String so leading zeros stay intact, then query your own inventory API.
Add the SwiftPM repository in Xcode or Package.swift and return exact barcode strings along with their symbology.
Add qrcode-barcode-scanner-swift on GitHub (also on the Swift Package Index listing) in Xcode or Package.swift, then link product QRCodeBarcodeScanner to your target.
SwiftPM downloads the prebuilt static XCFramework (QrcodeAiScannerFFI) pinned by SHA-256 checksum, needing 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, select 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).
Run scan(image:profile:) inside Task.detached, parse ScanReport leniently with Codable and keep the barcode symbologies your inventory workflow uses.
To test with a known sample, 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 required.
For a Code 128 label encoding STOCK-4827, readBarcodeImage returns BarcodeReading(symbology: "code128", text: "STOCK-4827"). A UPC-A code such as 012345678905 retains 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) packaging the shared Rust engine as a static XCFramework for decoding 16 1D and 2D barcode formats plus QR codes on iOS and macOS.
It reads 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 supports iOS 13+ (arm64), iOS Simulator 13+ (arm64, x86_64) and macOS 11+ (arm64, x86_64), requiring neither a Rust toolchain nor dynamic framework signing.
No. The scanner returns each encoded identifier as a String together with its symbology (and parsed GS1 fields when recognised), keeping leading zeros intact. Query your own product catalogue or inventory backend separately.
Your app owns AVFoundation capture, camera permissions and preview UI. Convert camera sample buffers into RGBA pixels and pass them to scanFrame(rgba:width:height:profile: "frame") off the main thread.
When no barcode is found, the SDK 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 runs locally on the device inside the statically linked library, with zero network calls, no QR Code AI account and no creation credits.
Yes. Current releases are published under the MIT licence for commercial App Store and enterprise software while retaining copyright and licence notices (see LICENSING.md). SDK use is independent of QR Code AI’s paid creation plans and seven-day Premium trial.