Skip to content

Commit e69f4de

Browse files
feat!: Hint input parameter and Format output parameter (#31)
* feat!: Support hint parameter in scanning References: https://outsystemsrd.atlassian.net/browse/RMET-2962 BREAKING CHANGE: This adds a new parameter to `scanBarcode` in `OSBARCManagerProtocol`, which is a breaking change * refactor!: Extract scan parameters to structure References: https://outsystemsrd.atlassian.net/browse/RMET-2962 BREAKING CHANGE: This modifies the signature of the public `scanBarcode`, but allows for easier addition of new parameters to avoid future breaking changes. * feat!: return scanned text and format References: https://outsystemsrd.atlassian.net/browse/RMET-2962 BREAKING CHANGE: This modifies the output of the public `scanBarcode`, but allows for easier addition of new output to avoid future breaking changes. * chore(ci): Use macos-14 instead of macos-latest Because macos-14 comes with more Xcode versions. To be addressed in https://outsystemsrd.atlassian.net/browse/RMET-4424 * chore(ci): Remove specific device requirement from unit tests * chore(ci): fix Fastfile * chore: fix unit tests * chore: revert formatting * docs: Update README and CHANGELOG References: https://outsystemsrd.atlassian.net/browse/RMET-2962
1 parent 37851e5 commit e69f4de

21 files changed

+203
-73
lines changed

.github/workflows/github_actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
test:
99
name: Unit-Tests
10-
runs-on: macos-latest
10+
runs-on: macos-14
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4

.github/workflows/prepare_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
jobs:
1717
build-and-release:
1818
if: github.ref == 'refs/heads/main'
19-
runs-on: macos-latest
19+
runs-on: macos-14
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4

.github/workflows/release_and_publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
post-merge:
1111
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.merged == true
12-
runs-on: macos-latest
12+
runs-on: macos-14
1313

1414
steps:
1515
- name: Checkout Repository

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ iOSInjectionProject/
9191
.swiftlint.yml
9292

9393
scripts/build/
94-
.DS_Store
94+
build/
95+
.DS_Store

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
**BREAKING CHANGE**: The signature of `scanBarcode` has been updated, both input and output.
10+
11+
- Add **hint** parameter to scan for specific barcode formats
12+
- Return the format of the scanned code inside the scan result.
13+
714
## 1.1.3
815
- Increase scanning area (https://outsystemsrd.atlassian.net/browse/RMET-3683).
916

OSBarcodeLib.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
630812572E5866D900536FE7 /* OSBARCScannerHint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630812562E5866C700536FE7 /* OSBARCScannerHint.swift */; };
11+
6308125D2E58902B00536FE7 /* OSBARCScannerHint+VNBarcodeSymbology.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6308125C2E58902100536FE7 /* OSBARCScannerHint+VNBarcodeSymbology.swift */; };
12+
6308125F2E5891ED00536FE7 /* OSBARCScanParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6308125E2E5891E700536FE7 /* OSBARCScanParameters.swift */; };
13+
630812612E589F5A00536FE7 /* OSBARCScanResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630812602E589F5600536FE7 /* OSBARCScanResult.swift */; };
1014
7507FC1B27FC2AAE003809F6 /* OSBarcodeLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7507FC1227FC2AAE003809F6 /* OSBarcodeLib.framework */; };
1115
750B35872AFA93B100F90083 /* OSBARCScannerViewConfigurationValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750B35862AFA93B100F90083 /* OSBARCScannerViewConfigurationValues.swift */; };
1216
7513C4852B03E86B005E81C4 /* OSBARCDeviceTypeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7513C4802B03E86B005E81C4 /* OSBARCDeviceTypeModel.swift */; };
@@ -70,6 +74,10 @@
7074
/* End PBXContainerItemProxy section */
7175

7276
/* Begin PBXFileReference section */
77+
630812562E5866C700536FE7 /* OSBARCScannerHint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSBARCScannerHint.swift; sourceTree = "<group>"; };
78+
6308125C2E58902100536FE7 /* OSBARCScannerHint+VNBarcodeSymbology.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OSBARCScannerHint+VNBarcodeSymbology.swift"; sourceTree = "<group>"; };
79+
6308125E2E5891E700536FE7 /* OSBARCScanParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSBARCScanParameters.swift; sourceTree = "<group>"; };
80+
630812602E589F5600536FE7 /* OSBARCScanResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSBARCScanResult.swift; sourceTree = "<group>"; };
7381
7507FC1227FC2AAE003809F6 /* OSBarcodeLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OSBarcodeLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7482
7507FC1A27FC2AAE003809F6 /* OSBarcodeLibTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OSBarcodeLibTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7583
750B35862AFA93B100F90083 /* OSBARCScannerViewConfigurationValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSBARCScannerViewConfigurationValues.swift; sourceTree = "<group>"; };
@@ -208,17 +216,21 @@
208216
758E6C142B0238F100FC16D9 /* Models */ = {
209217
isa = PBXGroup;
210218
children = (
219+
6308125E2E5891E700536FE7 /* OSBARCScanParameters.swift */,
211220
7513C4822B03E86B005E81C4 /* MappableProtocol */,
212221
758E6C152B0238FF00FC16D9 /* OSBARCCameraModel.swift */,
213222
7513C4802B03E86B005E81C4 /* OSBARCDeviceTypeModel.swift */,
214223
7513C4812B03E86B005E81C4 /* OSBARCOrientationModel.swift */,
224+
630812562E5866C700536FE7 /* OSBARCScannerHint.swift */,
225+
630812602E589F5600536FE7 /* OSBARCScanResult.swift */,
215226
);
216227
path = Models;
217228
sourceTree = "<group>";
218229
};
219230
758E6C172B0239C100FC16D9 /* Extensions */ = {
220231
isa = PBXGroup;
221232
children = (
233+
6308125C2E58902100536FE7 /* OSBARCScannerHint+VNBarcodeSymbology.swift */,
222234
758E6C182B0239E700FC16D9 /* AVCaptureDevice+OSBARCModelMappable.swift */,
223235
7513C48F2B03E922005E81C4 /* AVCaptureVideoOrientation+CustomInit.swift */,
224236
75183A152B7389EC00AFC687 /* Float+DecimalPlacesCleaner.swift */,
@@ -436,6 +448,7 @@
436448
buildActionMask = 2147483647;
437449
files = (
438450
75D20FEB2AF17C8E009AD84D /* OSBARCPermissionsBehaviour.swift in Sources */,
451+
630812572E5866D900536FE7 /* OSBARCScannerHint.swift in Sources */,
439452
750B35872AFA93B100F90083 /* OSBARCScannerViewConfigurationValues.swift in Sources */,
440453
75183A162B7389EC00AFC687 /* Float+DecimalPlacesCleaner.swift in Sources */,
441454
756E17452B754B6400D594DA /* OSBARCCameraManager.swift in Sources */,
@@ -453,6 +466,7 @@
453466
75562B3F2B1767C100F31AF6 /* UIApplication+Window.swift in Sources */,
454467
75D20FE72AF17AFC009AD84D /* OSBARCCoordinatorProtocol.swift in Sources */,
455468
75D20FE22AF16B0A009AD84D /* OSBARCManagerFactory.swift in Sources */,
469+
630812612E589F5A00536FE7 /* OSBARCScanResult.swift in Sources */,
456470
75EF59A42B0E4A410084F144 /* OSBARCScanButton.swift in Sources */,
457471
75183A182B73936500AFC687 /* OSBARCZoomSelectorView.swift in Sources */,
458472
75D20FDC2AF16AC9009AD84D /* OSBARCManager.swift in Sources */,
@@ -474,7 +488,9 @@
474488
755AB5882B768425006B6507 /* OSBARCCaptureOutputDecoder.swift in Sources */,
475489
7513C4872B03E86B005E81C4 /* OSBARCDeviceTypeModelMappable.swift in Sources */,
476490
75EF59A02B0E44660084F144 /* OSBARCInstructionsText.swift in Sources */,
491+
6308125F2E5891ED00536FE7 /* OSBARCScanParameters.swift in Sources */,
477492
7513C4882B03E86B005E81C4 /* OSBARCModelMappable.swift in Sources */,
493+
6308125D2E58902B00536FE7 /* OSBARCScannerHint+VNBarcodeSymbology.swift in Sources */,
478494
7513C4862B03E86B005E81C4 /* OSBARCOrientationModel.swift in Sources */,
479495
75EF599A2B0E2F220084F144 /* OSBARCBackgroundView.swift in Sources */,
480496
7513C4852B03E86B005E81C4 /* OSBARCDeviceTypeModel.swift in Sources */,

OSBarcodeLib/Manager/OSBARCManager.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,25 @@ struct OSBARCManager {
3333

3434
/// Implementation of the `OSBARCManagerProtocol` methods.
3535
extension OSBARCManager: OSBARCManagerProtocol {
36-
func scanBarcode(with instructionsText: String, _ buttonText: String?, _ cameraModel: OSBARCCameraModel, and orientationModel: OSBARCOrientationModel) async throws -> String {
36+
func scanBarcode(with parameters: OSBARCScanParameters) async throws -> OSBARCScanResult {
3737
// validates if the user has access to the device's camera.
3838
let hasCameraAccess = await self.permissionsBehaviour.hasCameraAccess()
3939
if !hasCameraAccess { throw OSBARCManagerError.cameraAccessDenied }
4040
// requests the scanner to start, treating its result value.
4141
return try await withCheckedThrowingContinuation {
42-
self.startScanning(with: instructionsText, buttonText, cameraModel, and: orientationModel, continuation: $0)
42+
self.startScanning(with: parameters, continuation: $0)
4343
}
4444
}
4545

4646
/// Triggers the scanner view.
4747
/// - Parameters:
48-
/// - instructionsText: Text to be displayed on the scanner view.
49-
/// - buttonText: Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
50-
/// - cameraModel: Camera to use for input gathering.
51-
/// - orientationModel: Scanner view's orientation.
48+
/// - parameters: The full parameter list to configure the scanner
5249
/// - continuation: Object responsible for returning the method's result to its caller.
53-
private func startScanning(
54-
with instructionsText: String,
55-
_ buttonText: String?,
56-
_ cameraModel: OSBARCCameraModel,
57-
and orientationModel: OSBARCOrientationModel,
58-
continuation: CheckedContinuation<String, any Error>
59-
) {
50+
private func startScanning(with parameters: OSBARCScanParameters, continuation: CheckedContinuation<OSBARCScanResult, any Error>) {
6051
DispatchQueue.main.async {
61-
self.scannerBehaviour.startScanning(with: instructionsText, buttonText, cameraModel, and: orientationModel) { scannedCode in
62-
if !scannedCode.isEmpty {
63-
continuation.resume(returning: scannedCode)
52+
self.scannerBehaviour.startScanning(with: parameters) { scanResult in
53+
if !scanResult.text.isEmpty {
54+
continuation.resume(returning: scanResult)
6455
} else {
6556
continuation.resume(throwing: OSBARCManagerError.scanningCancelled)
6657
}

OSBarcodeLib/Manager/OSBARCManagerProtocol.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public protocol OSBARCManagerProtocol {
55
/// `cameraAccessDenied`: If camera access has not been given.
66
/// `scanningCancelled`: If scanning has been cancelled.
77
/// - Parameters:
8-
/// - instructionsText: Text to be displayed on the scanner view.
9-
/// - buttonText: Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
10-
/// - cameraModel: Camera to use for input gathering.
11-
/// - orientationModel: Scanner view's orientation.
8+
/// - parameters: The full parameter list to configure the scanner
129
/// - Returns: When successful, it returns the text associated with the scanned barcode.
13-
func scanBarcode(with instructionsText: String, _ buttonText: String?, _ cameraModel: OSBARCCameraModel, and orientationModel: OSBARCOrientationModel) async throws -> String
10+
func scanBarcode(with parameters: OSBARCScanParameters) async throws -> OSBARCScanResult
1411
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public struct OSBARCScanParameters {
2+
/// Text to be displayed on the scanner view.
3+
public let scanInstructions: String
4+
5+
/// Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
6+
public let scanButtonText: String?
7+
8+
// Camera to use for input gathering.
9+
public let cameraDirection: OSBARCCameraModel
10+
11+
// Scanner view's orientation.
12+
public let scanOrientation: OSBARCOrientationModel
13+
14+
// The optional hint, to scan a specific format (e.g. only qr code). `Nil` or `unknown` value means it can scan all.
15+
public let hint: OSBARCScannerHint?
16+
17+
public init(scanInstructions: String,
18+
scanButtonText: String?,
19+
cameraDirection: OSBARCCameraModel,
20+
scanOrientation: OSBARCOrientationModel,
21+
hint: OSBARCScannerHint?) {
22+
self.scanInstructions = scanInstructions
23+
self.scanButtonText = scanButtonText
24+
self.cameraDirection = cameraDirection
25+
self.scanOrientation = scanOrientation
26+
self.hint = hint
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public struct OSBARCScanResult: Equatable {
2+
/// The actual textual data that was scanned
3+
public let text: String
4+
5+
/// The format that was scanned, or `unknown` if unable to determine
6+
public let format: OSBARCScannerHint
7+
}
8+
9+
extension OSBARCScanResult {
10+
static func empty() -> OSBARCScanResult {
11+
return OSBARCScanResult(text: "", format: .unknown)
12+
}
13+
}

0 commit comments

Comments
 (0)