Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/barcode-gs1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
barcode-scanner: minor
barcode-scanner-js: minor
---

Added support for GS1 DataBar on iOS 15.4+
2 changes: 1 addition & 1 deletion plugins/barcode-scanner/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion plugins/barcode-scanner/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,36 @@ export type { PermissionState } from '@tauri-apps/api/core'

export enum Format {
QRCode = 'QR_CODE',
/**
* Not supported on iOS.
*/
UPC_A = 'UPC_A',
UPC_E = 'UPC_E',
EAN8 = 'EAN_8',
EAN13 = 'EAN_13',
Code39 = 'CODE_39',
Code93 = 'CODE_93',
Code128 = 'CODE_128',
/**
* Not supported on iOS.
*/
Codabar = 'CODABAR',
ITF = 'ITF',
Aztec = 'AZTEC',
DataMatrix = 'DATA_MATRIX',
PDF417 = 'PDF_417'
PDF417 = 'PDF_417',
/**
* Not supported on Android. Requires iOS 15.4+
*/
GS1DataBar = 'GS1_DATA_BAR',
/**
* Not supported on Android. Requires iOS 15.4+
*/
GS1DataBarLimited = 'GS1_DATA_BAR_LIMITED',
/**
* Not supported on Android. Requires iOS 15.4+
*/
GS1DataBarExpanded = 'GS1_DATA_BAR_EXPANDED'
}

export interface ScanOptions {
Expand Down
40 changes: 34 additions & 6 deletions plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ enum SupportedFormat: String, CaseIterable, Decodable {
case DATA_MATRIX
case PDF_417
case QR_CODE
case GS1_DATA_BAR
case GS1_DATA_BAR_LIMITED
case GS1_DATA_BAR_EXPANDED

var value: AVMetadataObject.ObjectType {
var value: AVMetadataObject.ObjectType? {
switch self {
case .UPC_E: return AVMetadataObject.ObjectType.upce
case .EAN_8: return AVMetadataObject.ObjectType.ean8
Expand All @@ -41,6 +44,24 @@ enum SupportedFormat: String, CaseIterable, Decodable {
case .DATA_MATRIX: return AVMetadataObject.ObjectType.dataMatrix
case .PDF_417: return AVMetadataObject.ObjectType.pdf417
case .QR_CODE: return AVMetadataObject.ObjectType.qr
case .GS1_DATA_BAR:
if #available(iOS 15.4, *) {
return AVMetadataObject.ObjectType.gs1DataBar
} else {
return nil
}
case .GS1_DATA_BAR_LIMITED:
if #available(iOS 15.4, *) {
return AVMetadataObject.ObjectType.gs1DataBarLimited
} else {
return nil
}
case .GS1_DATA_BAR_EXPANDED:
if #available(iOS 15.4, *) {
return AVMetadataObject.ObjectType.gs1DataBarExpanded
} else {
return nil
}
}
}
}
Expand Down Expand Up @@ -242,13 +263,20 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
scanFormats = [AVMetadataObject.ObjectType]()

(args.formats ?? []).forEach { format in
scanFormats.append(format.value)
if let formatValue = format.value {
scanFormats.append(formatValue)
} else {
invoke.reject("Unsupported barcode format on this iOS version: \(format)")
return
}
}

if scanFormats.count == 0 {
for supportedFormat in SupportedFormat.allCases {
scanFormats.append(supportedFormat.value)
}
if scanFormats.isEmpty {
for supportedFormat in SupportedFormat.allCases {
if let formatValue = supportedFormat.value {
scanFormats.append(formatValue)
}
}
}

self.metaOutput!.metadataObjectTypes = self.scanFormats
Expand Down
9 changes: 9 additions & 0 deletions plugins/barcode-scanner/ios/Sources/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func discoverCaptureDevices() -> [AVCaptureDevice] {
}

func formatStringFromMetadata(_ type: AVMetadataObject.ObjectType) -> String {
if #available(iOS 15.4, *) {
if type == .gs1DataBar {
return "GS1_DATA_BAR"
} else if type == .gs1DataBarLimited {
return "GS1_DATA_BAR_LIMITED"
} else if type == .gs1DataBarExpanded {
return "GS1_DATA_BAR_EXPANDED"
}
}
switch type {
case AVMetadataObject.ObjectType.upce:
return "UPC_E"
Expand Down
Loading