iOS Barcode Scanner SDK

Add offline 1D and 2D barcode scanning to your iOS and macOS Swift apps. Link the MIT-licensed static XCFramework via Swift Package Manager without Rust setup, decode label images or RGBA frames off the main thread and keep exact string identifiers.

Swift
import Foundation
import QRCodeBarcodeScanner

let json = try scan(image: imageData, profile: "frame")
let report = try JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any]
let rows = report?["detections"] as? [[String: Any]] ?? []
let barcode = rows.first { $0["symbology"] as? String == "code128" }
let content = barcode?["content"] as? [String: Any]

print(content?["text"] as? String ?? "")

Inspect the decoded identifierSTOCK-4827

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.

Swift
// 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")
        ]
    )
]

Need to scan a barcode right now? Open the online reader

iOS Barcode Scanner SDK at a glance

  • Checksum-pinned static XCFramework

    SwiftPM

  • arm64 devices & arm64/x86_64 sims

    iOS 13+ · macOS 11+

  • EAN, UPC, Code 128, Data Matrix & more

    1D + 2D

  • Open-source licence

    MIT

Bring offline barcode scanning to iOS and macOS

Decode 1D retail, warehouse and 2D matrix labels in Swift with a static XCFramework while your app retains full control over AVFoundation.

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.

Scan RGBA camera frames

Pass raw RGBA pixels from AVFoundation to scanFrame(rgba:width:height:profile:) off the main thread for smooth live capture.

Keep exact strings & formats

Decode each detection’s symbology and content.text as Swift String so leading zeros stay intact, then query your own inventory API.

Add barcode image reading in Swift on iOS

Add the SwiftPM repository in Xcode or Package.swift and return exact barcode strings along with their symbology.

Add QRCodeBarcodeScanner with SwiftPM

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.

Swift
// 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).

Decode a barcode image off the main thread

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.

Swift
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.

Inspect the decoded identifier

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.

XCFramework architecture, barcode formats and data handling

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.

Swift Barcode Scanner documentation and licence

Official package documentation, ScanReport specification and licensing references.

iOS Barcode Scanner SDK questions

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.