Skip to content

Commit aa9140e

Browse files
enkhjileFabianLars
andauthored
feat(barcode-scanner): Add support for GS1 DataBar on iOS 15.4+ (#2437)
Co-authored-by: Fabian-Lars <[email protected]>
1 parent 6a8f255 commit aa9140e

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed

.changes/barcode-gs1.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
barcode-scanner: minor
3+
barcode-scanner-js: minor
4+
---
5+
6+
Added support for GS1 DataBar on iOS 15.4+

plugins/barcode-scanner/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/barcode-scanner/guest-js/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,36 @@ export type { PermissionState } from '@tauri-apps/api/core'
1212

1313
export enum Format {
1414
QRCode = 'QR_CODE',
15+
/**
16+
* Not supported on iOS.
17+
*/
1518
UPC_A = 'UPC_A',
1619
UPC_E = 'UPC_E',
1720
EAN8 = 'EAN_8',
1821
EAN13 = 'EAN_13',
1922
Code39 = 'CODE_39',
2023
Code93 = 'CODE_93',
2124
Code128 = 'CODE_128',
25+
/**
26+
* Not supported on iOS.
27+
*/
2228
Codabar = 'CODABAR',
2329
ITF = 'ITF',
2430
Aztec = 'AZTEC',
2531
DataMatrix = 'DATA_MATRIX',
26-
PDF417 = 'PDF_417'
32+
PDF417 = 'PDF_417',
33+
/**
34+
* Not supported on Android. Requires iOS 15.4+
35+
*/
36+
GS1DataBar = 'GS1_DATA_BAR',
37+
/**
38+
* Not supported on Android. Requires iOS 15.4+
39+
*/
40+
GS1DataBarLimited = 'GS1_DATA_BAR_LIMITED',
41+
/**
42+
* Not supported on Android. Requires iOS 15.4+
43+
*/
44+
GS1DataBarExpanded = 'GS1_DATA_BAR_EXPANDED'
2745
}
2846

2947
export interface ScanOptions {

plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ enum SupportedFormat: String, CaseIterable, Decodable {
2727
case DATA_MATRIX
2828
case PDF_417
2929
case QR_CODE
30+
case GS1_DATA_BAR
31+
case GS1_DATA_BAR_LIMITED
32+
case GS1_DATA_BAR_EXPANDED
3033

31-
var value: AVMetadataObject.ObjectType {
34+
var value: AVMetadataObject.ObjectType? {
3235
switch self {
3336
case .UPC_E: return AVMetadataObject.ObjectType.upce
3437
case .EAN_8: return AVMetadataObject.ObjectType.ean8
@@ -41,6 +44,24 @@ enum SupportedFormat: String, CaseIterable, Decodable {
4144
case .DATA_MATRIX: return AVMetadataObject.ObjectType.dataMatrix
4245
case .PDF_417: return AVMetadataObject.ObjectType.pdf417
4346
case .QR_CODE: return AVMetadataObject.ObjectType.qr
47+
case .GS1_DATA_BAR:
48+
if #available(iOS 15.4, *) {
49+
return AVMetadataObject.ObjectType.gs1DataBar
50+
} else {
51+
return nil
52+
}
53+
case .GS1_DATA_BAR_LIMITED:
54+
if #available(iOS 15.4, *) {
55+
return AVMetadataObject.ObjectType.gs1DataBarLimited
56+
} else {
57+
return nil
58+
}
59+
case .GS1_DATA_BAR_EXPANDED:
60+
if #available(iOS 15.4, *) {
61+
return AVMetadataObject.ObjectType.gs1DataBarExpanded
62+
} else {
63+
return nil
64+
}
4465
}
4566
}
4667
}
@@ -242,13 +263,20 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
242263
scanFormats = [AVMetadataObject.ObjectType]()
243264

244265
(args.formats ?? []).forEach { format in
245-
scanFormats.append(format.value)
266+
if let formatValue = format.value {
267+
scanFormats.append(formatValue)
268+
} else {
269+
invoke.reject("Unsupported barcode format on this iOS version: \(format)")
270+
return
271+
}
246272
}
247273

248-
if scanFormats.count == 0 {
249-
for supportedFormat in SupportedFormat.allCases {
250-
scanFormats.append(supportedFormat.value)
251-
}
274+
if scanFormats.isEmpty {
275+
for supportedFormat in SupportedFormat.allCases {
276+
if let formatValue = supportedFormat.value {
277+
scanFormats.append(formatValue)
278+
}
279+
}
252280
}
253281

254282
self.metaOutput!.metadataObjectTypes = self.scanFormats

plugins/barcode-scanner/ios/Sources/Utils.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func discoverCaptureDevices() -> [AVCaptureDevice] {
5252
}
5353

5454
func formatStringFromMetadata(_ type: AVMetadataObject.ObjectType) -> String {
55+
if #available(iOS 15.4, *) {
56+
if type == .gs1DataBar {
57+
return "GS1_DATA_BAR"
58+
} else if type == .gs1DataBarLimited {
59+
return "GS1_DATA_BAR_LIMITED"
60+
} else if type == .gs1DataBarExpanded {
61+
return "GS1_DATA_BAR_EXPANDED"
62+
}
63+
}
5564
switch type {
5665
case AVMetadataObject.ObjectType.upce:
5766
return "UPC_E"

0 commit comments

Comments
 (0)