From a2afc2a7e098ed3adf6cf57a046a77a5f66a56ca Mon Sep 17 00:00:00 2001 From: scanbot-ci Date: Tue, 15 Jul 2025 16:02:45 +0200 Subject: [PATCH 01/17] Copied Barcode SDK code snippets for release v8.0.0. --- .../BarcodesOverlayViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift index f28bb9a..351b41d 100644 --- a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift +++ b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift @@ -56,10 +56,10 @@ class BarcodesOverlayViewController: UIViewController { trackingConfiguration.textStyle.textBackgroundColor = UIColor(red:0, green:0.81, blue:0.65, alpha:0.8) // Set the text color of the selected tracked barcodes. - trackingConfiguration.textStyle.selectedTextColor = UIColor.white + trackingConfiguration.textStyle.highlightedTextColor = UIColor.white // Set the text background color of the selected tracked barcodes. - trackingConfiguration.textStyle.textBackgroundSelectedColor = UIColor(red:0.784, green:0.1, blue:0.235, alpha:0.8) + trackingConfiguration.textStyle.textBackgroundHighlightedColor = UIColor(red:0.784, green:0.1, blue:0.235, alpha:0.8) // Set the text format of the tracked barcodes. trackingConfiguration.textStyle.trackingOverlayTextFormat = .codeAndType From de5e0656d6f950dc57dd2ed40799f1f3f63f4d9c Mon Sep 17 00:00:00 2001 From: scanbot-ci Date: Fri, 19 Sep 2025 17:39:52 +0200 Subject: [PATCH 02/17] Copied Barcode SDK code snippets for release v8.0.0. --- .../BarcodeScanAndCountViewController.swift | 2 +- .../BarcodeScannerViewController.swift | 2 +- .../BarcodeDetectionOnImage.swift | 30 ++++++++++------ .../BarcodesBatchViewController.swift | 2 +- .../BarcodesOverlayViewController.swift | 7 ++-- .../BarcodeDataParserViewController.swift | 2 +- .../Data Parser/ManualDataParser.swift | 35 ++++++++++++------- 7 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift index fc8579e..7dbfe56 100644 --- a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift +++ b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift @@ -71,7 +71,7 @@ extension BarcodeScanAndCountViewController: SBSDKBarcodeScanAndCountViewControl for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift index 9402995..0f57a15 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift @@ -80,7 +80,7 @@ extension BarcodeScannerViewController: SBSDKBarcodeScannerViewControllerDelegat for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift index bbf6152..c60b639 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift @@ -25,16 +25,24 @@ func detectBarcodesOnImage() { // Enable the barcode image extraction. configuration.returnBarcodeImage = true - // Create an instance of `SBSDKBarcodeScanner`, passing the configuration. - let scanner = SBSDKBarcodeScanner(configuration: configuration) - - // Returns the barcode scan result. - let result = scanner.scan(from: image) - - guard let result = result else { return } - - for barcodeItem in result.barcodes { - // Get the source image. - let sourceImage = barcodeItem.sourceImage?.toUIImage() + do { + + // Create an instance of barcode scanner, passing the configuration. + let scanner = try SBSDKBarcodeScanner(configuration: configuration) + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run the scanner on the image. + let result = try scanner.run(image: imageRef) + + for barcodeItem in result.barcodes { + + // Get the source image. + let sourceImage = try barcodeItem.sourceImage?.toUIImage() + } + } + catch { + print("Error detecting barcode: \(error.localizedDescription)") } } diff --git a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift index 9e7847d..44d1573 100644 --- a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift +++ b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift @@ -79,7 +79,7 @@ extension BarcodesBatchViewController: SBSDKBarcodeScannerViewControllerDelegate for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift index 351b41d..020c33d 100644 --- a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift +++ b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift @@ -78,8 +78,7 @@ extension BarcodesOverlayViewController: SBSDKBarcodeTrackingOverlayControllerDe print(barcode) // Get the source image. - let sourceImage = barcode.sourceImage?.toUIImage() - + let sourceImage = try? barcode.sourceImage?.toUIImage() } // Implement this method if you need to customize the polygon style individually for each barcode detected. @@ -93,7 +92,9 @@ extension BarcodesOverlayViewController: SBSDKBarcodeTrackingOverlayControllerDe } // Implement this method if you need to customize the text style individually for each barcode detected. - func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController, textStyleFor barcode: SBSDKBarcodeItem) -> SBSDKBarcodeTrackedViewTextStyle? { + func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController, + textStyleFor barcode: SBSDKBarcodeItem, + proposedStyle: SBSDKBarcodeTrackedViewTextStyle) -> SBSDKBarcodeTrackedViewTextStyle { let style = SBSDKBarcodeTrackedViewTextStyle() if barcode.format == SBSDKBarcodeFormat.qrCode { style.textBackgroundColor = UIColor.purple.withAlphaComponent(0.2) diff --git a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift index c908497..90bd3ec 100644 --- a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift +++ b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift @@ -83,7 +83,7 @@ extension BarcodeDataParserViewController: SBSDKBarcodeScannerViewControllerDele let barcode = codes.first // Get the source image. - let sourceImage = barcode?.sourceImage?.toUIImage() + let sourceImage = try? barcode?.sourceImage?.toUIImage() // Run the parser and check the result. if let document = SBSDKBarcodeDocumentModelSwissQR(document: barcode?.extractedDocument) { diff --git a/Documentation Code Snippets/Data Parser/ManualDataParser.swift b/Documentation Code Snippets/Data Parser/ManualDataParser.swift index bcc68fc..8bfeb04 100644 --- a/Documentation Code Snippets/Data Parser/ManualDataParser.swift +++ b/Documentation Code Snippets/Data Parser/ManualDataParser.swift @@ -13,25 +13,34 @@ func parseDataManually() { // Some raw barcode string. let rawBarcodeString = "(01)02804086001986(3103)000220(15)220724(30)01(3922)00198" - // Instantiate the parser. - let parser = SBSDKBarcodeDocumentParser(extractedDocumentFormats: [.gs1]) - - // Run the parser and check the result. - if let document = parser.parse(from: rawBarcodeString) { + do { + + // Instantiate the parser. + let parser = try? SBSDKBarcodeDocumentParser(acceptedFormats: [.gs1]) - // Parse the resulted document as a GS1 document. - if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: document) { + // Run the parser and check the result. + if let document = try? parser?.parse(rawString: rawBarcodeString) { - // Retrieve the elements. - let elements = gs1ParsedDocument.elements + // Get the parsed document. + guard let parsedDocument = document.parsedDocument else { return } - // Enumerate over the elements. - for element in elements { + // Parse the resulted document as a GS1 document. + if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: parsedDocument) { - // Do something with the element. + // Retrieve the elements. + let elements = gs1ParsedDocument.elements - print("\(element.dataTitle?.value?.text) = \(element.rawValue?.value?.text)") + // Enumerate over the elements. + for element in elements { + + // Do something with the element. + + print("\(element.dataTitle?.value?.text) = \(element.rawValue?.value?.text)") + } } } } + catch { + print("Error parsing document: \(error.localizedDescription)") + } } From ff85cdc53e7af27ce2c1e4d4bd82a77f9b0d75ef Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Wed, 15 Oct 2025 13:52:18 +0200 Subject: [PATCH 03/17] update code snippets --- ...erlayBarcodeScannerUI2ViewController.swift | 2 +- ...ionBarConfigurationUI2ViewController.swift | 2 +- ...ppingBarcodeScannerUI2ViewController.swift | 2 +- ...tipleBarcodeScannerUI2ViewController.swift | 2 +- .../BarcodePaletteUI2ViewController.swift | 2 +- .../BarcodesSheetModeUI2ViewController.swift | 2 +- ...ingleBarcodeScannerUI2ViewController.swift | 2 +- .../SwiftUI/BarcodeScannerSwiftUIView.swift | 2 +- .../TopBarBarcodeUI2ViewController.swift | 2 +- ...BarcodeUserGuidanceUI2ViewController.swift | 2 +- .../BarcodeScanAndCountViewController.swift | 2 +- .../BarcodeScannerViewController.swift | 2 +- .../BarcodeDetectionOnImage.swift | 30 ++++++++++------ .../BarcodesBatchViewController.swift | 2 +- .../BarcodesOverlayViewController.swift | 7 ++-- .../BarcodeDataParserViewController.swift | 2 +- .../Data Parser/ManualDataParser.swift | 35 ++++++++++++------- 17 files changed, 59 insertions(+), 41 deletions(-) diff --git a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift index b59ee47..ba912f1 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift @@ -36,7 +36,7 @@ class AROverlayBarcodeScannerUI2ViewController: UIViewController { configuration.useCase = usecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift index 2a07247..7a2f404 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift @@ -51,7 +51,7 @@ class ActionBarConfigurationUI2ViewController: UIViewController { actionBar.flipCameraButton.foregroundColor = SBSDKUI2Color(colorString: "#FFFFFF") // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift index d6dff3c..3b1b06d 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift @@ -59,7 +59,7 @@ class InfoMappingBarcodeScannerUI2ViewController: UIViewController { configuration.useCase = usecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift index 9d48fe8..f0a1a34 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift @@ -48,7 +48,7 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { configuration.useCase = multiUsecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift index e0b88b0..6a1543c 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift @@ -48,7 +48,7 @@ class BarcodePaletteUI2ViewController: UIViewController { configuration.palette = palette // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift index a29c69d..d565a5b 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift @@ -39,7 +39,7 @@ class BarcodesSheetModeUI2ViewController: UIViewController { configuration.useCase = multiUsecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift index ab0b76f..2d8990f 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift @@ -54,7 +54,7 @@ class SingleBarcodeScannerUI2ViewController: UIViewController { configuration.useCase = singleUsecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift b/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift index 718d807..c4928e4 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift @@ -51,7 +51,7 @@ struct BarcodeScannerSwiftUIView: View { configuration.useCase = singleUsecase // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) return configuration }() diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift index 640960f..4e78331 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift @@ -36,7 +36,7 @@ class TopBarBarcodeUI2ViewController: UIViewController { configuration.topBar.cancelButton.foreground.color = SBSDKUI2Color(colorString: "#FFFFFF") // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift index c931038..20a66f7 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift @@ -36,7 +36,7 @@ class BarcodeUserGuidanceUI2ViewController: UIViewController { userGuidance.background.fillColor = SBSDKUI2Color(colorString: "#7A000000") // Create and set an array of accepted barcode formats. - configuration.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.twod + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, diff --git a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift index fc8579e..7dbfe56 100644 --- a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift +++ b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift @@ -71,7 +71,7 @@ extension BarcodeScanAndCountViewController: SBSDKBarcodeScanAndCountViewControl for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift index 9402995..0f57a15 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift @@ -80,7 +80,7 @@ extension BarcodeScannerViewController: SBSDKBarcodeScannerViewControllerDelegat for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift index bbf6152..c60b639 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/DetectionOnImage/BarcodeDetectionOnImage.swift @@ -25,16 +25,24 @@ func detectBarcodesOnImage() { // Enable the barcode image extraction. configuration.returnBarcodeImage = true - // Create an instance of `SBSDKBarcodeScanner`, passing the configuration. - let scanner = SBSDKBarcodeScanner(configuration: configuration) - - // Returns the barcode scan result. - let result = scanner.scan(from: image) - - guard let result = result else { return } - - for barcodeItem in result.barcodes { - // Get the source image. - let sourceImage = barcodeItem.sourceImage?.toUIImage() + do { + + // Create an instance of barcode scanner, passing the configuration. + let scanner = try SBSDKBarcodeScanner(configuration: configuration) + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run the scanner on the image. + let result = try scanner.run(image: imageRef) + + for barcodeItem in result.barcodes { + + // Get the source image. + let sourceImage = try barcodeItem.sourceImage?.toUIImage() + } + } + catch { + print("Error detecting barcode: \(error.localizedDescription)") } } diff --git a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift index 9e7847d..44d1573 100644 --- a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift +++ b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift @@ -79,7 +79,7 @@ extension BarcodesBatchViewController: SBSDKBarcodeScannerViewControllerDelegate for code in codes { // Get the source image. - let sourceImage = code.sourceImage?.toUIImage() + let sourceImage = try? code.sourceImage?.toUIImage() } } diff --git a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift index 351b41d..020c33d 100644 --- a/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift +++ b/Documentation Code Snippets/BarcodesOverlayScanner/BarcodesOverlayViewController.swift @@ -78,8 +78,7 @@ extension BarcodesOverlayViewController: SBSDKBarcodeTrackingOverlayControllerDe print(barcode) // Get the source image. - let sourceImage = barcode.sourceImage?.toUIImage() - + let sourceImage = try? barcode.sourceImage?.toUIImage() } // Implement this method if you need to customize the polygon style individually for each barcode detected. @@ -93,7 +92,9 @@ extension BarcodesOverlayViewController: SBSDKBarcodeTrackingOverlayControllerDe } // Implement this method if you need to customize the text style individually for each barcode detected. - func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController, textStyleFor barcode: SBSDKBarcodeItem) -> SBSDKBarcodeTrackedViewTextStyle? { + func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController, + textStyleFor barcode: SBSDKBarcodeItem, + proposedStyle: SBSDKBarcodeTrackedViewTextStyle) -> SBSDKBarcodeTrackedViewTextStyle { let style = SBSDKBarcodeTrackedViewTextStyle() if barcode.format == SBSDKBarcodeFormat.qrCode { style.textBackgroundColor = UIColor.purple.withAlphaComponent(0.2) diff --git a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift index c908497..90bd3ec 100644 --- a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift +++ b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift @@ -83,7 +83,7 @@ extension BarcodeDataParserViewController: SBSDKBarcodeScannerViewControllerDele let barcode = codes.first // Get the source image. - let sourceImage = barcode?.sourceImage?.toUIImage() + let sourceImage = try? barcode?.sourceImage?.toUIImage() // Run the parser and check the result. if let document = SBSDKBarcodeDocumentModelSwissQR(document: barcode?.extractedDocument) { diff --git a/Documentation Code Snippets/Data Parser/ManualDataParser.swift b/Documentation Code Snippets/Data Parser/ManualDataParser.swift index bcc68fc..8bfeb04 100644 --- a/Documentation Code Snippets/Data Parser/ManualDataParser.swift +++ b/Documentation Code Snippets/Data Parser/ManualDataParser.swift @@ -13,25 +13,34 @@ func parseDataManually() { // Some raw barcode string. let rawBarcodeString = "(01)02804086001986(3103)000220(15)220724(30)01(3922)00198" - // Instantiate the parser. - let parser = SBSDKBarcodeDocumentParser(extractedDocumentFormats: [.gs1]) - - // Run the parser and check the result. - if let document = parser.parse(from: rawBarcodeString) { + do { + + // Instantiate the parser. + let parser = try? SBSDKBarcodeDocumentParser(acceptedFormats: [.gs1]) - // Parse the resulted document as a GS1 document. - if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: document) { + // Run the parser and check the result. + if let document = try? parser?.parse(rawString: rawBarcodeString) { - // Retrieve the elements. - let elements = gs1ParsedDocument.elements + // Get the parsed document. + guard let parsedDocument = document.parsedDocument else { return } - // Enumerate over the elements. - for element in elements { + // Parse the resulted document as a GS1 document. + if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: parsedDocument) { - // Do something with the element. + // Retrieve the elements. + let elements = gs1ParsedDocument.elements - print("\(element.dataTitle?.value?.text) = \(element.rawValue?.value?.text)") + // Enumerate over the elements. + for element in elements { + + // Do something with the element. + + print("\(element.dataTitle?.value?.text) = \(element.rawValue?.value?.text)") + } } } } + catch { + print("Error parsing document: \(error.localizedDescription)") + } } From 1b79168e3d368d2c5cf8e572a3d5dd3a17abfcfc Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Fri, 17 Oct 2025 13:15:58 +0200 Subject: [PATCH 04/17] update code snippets --- ...rcodeGettingStartedUI2ViewController.swift | 86 ++++++++++++ .../TinyBarcodeScannerUI2ViewController.swift | 38 +++++ .../BarcodeViewFinderUI2ViewController.swift | 55 ++++++++ .../BarcodeHandlingResultViewController.swift | 70 ++++++++++ .../BarcodeGeneralConfiguration.swift | 130 ++++++++++++++++++ ...odeImageResultHandlingViewController.swift | 76 ++++++++++ ...rcodeRawResultHandlingViewController.swift | 80 +++++++++++ 7 files changed, 535 insertions(+) create mode 100644 Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift create mode 100644 Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift create mode 100644 Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift create mode 100644 Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift create mode 100644 Documentation Code Snippets/General Scanner Configuration/BarcodeGeneralConfiguration.swift create mode 100644 Documentation Code Snippets/Result Handling/Image/BarcodeImageResultHandlingViewController.swift create mode 100644 Documentation Code Snippets/Result Handling/Raw values/BarcodeRawResultHandlingViewController.swift diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift new file mode 100644 index 0000000..b3e7fcc --- /dev/null +++ b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift @@ -0,0 +1,86 @@ +// +// BarcodeGettingStartedUI2ViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeGettingStartedUI2ViewController: UIViewController { + + func launchRTUUIv2Scanner() { + + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Present the scanner view controller modally on this view controller. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) { controller, cancelled, error, result in + + // Completion handler to process the result. + // The `cancelled` parameter indicates if the cancel button was tapped. + + controller.presentingViewController?.dismiss(animated: true) + } + } + + func handleScanResults() { + + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Present the scanner view controller modally on this view controller. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) { controller, cancelled, error, result in + + if cancelled { + + // Indicates that the cancel button was tapped. + controller.presentingViewController?.dismiss(animated: true) + + } else if let items = result?.items { + + // Process result + items.forEach({ item in + + print("Barcode Identity String: \(item.barcode.identityString)") + print("Scan count: \(item.count)") + print("Barcode Text: \(item.barcode.text)") + print("Barcode Text with Extension: \(item.barcode.textWithExtension)") + print("Barcode Format: \(item.barcode.format)") + + // Retrieve the extracted (known) document. + // e.g Boarding Pass + if let boardingPass = SBSDKBarcodeDocumentModelBoardingPass(document: item.barcode.extractedDocument) { + + if let passengerName = boardingPass.passengerName { + print("Passenger name: \(passengerName)") + } + print("Number of legs: \(boardingPass.legs)") + + boardingPass.legs.forEach({ (leg) in + print("Flight number: \(leg.flightNumber?.value?.text ?? "")") + print("Seat number: \(leg.seatNumber?.value?.text ?? "")") + print("Date of flight julian: \(leg.dateOfFlightJulian?.value?.text ?? "")") + print("Departure Airport code: \(leg.departureAirportCode?.value?.text ?? "")") + print("Destination Airport code: \(leg.destinationAirportCode?.value?.text ?? "")") + + // or print all fields. + leg.document.fields.forEach({ field in + print("\n" + "\(field.type.displayText ?? ""): \(field.value?.text ?? "")") + }) + }) + + // or print all fields. + boardingPass.document.fields.forEach({ field in + print("\n" + "\(field.type.displayText ?? ""): \(field.value?.text ?? "")") + }) + } + + }) + } + } + } +} diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift new file mode 100644 index 0000000..c34ba36 --- /dev/null +++ b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift @@ -0,0 +1,38 @@ +// +// TinyBarcodeScannerUI2ViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 17.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class TinyBarcodeScannerUI2ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Start scanning here. Usually this is an action triggered by some button or menu. + self.startScanning() + } + + func startScanning() { + + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Enable locking the focus at the minimum possible distance. + configuration.cameraConfiguration.minFocusDistanceLock = true + + // Present the scanner view controller modally on this view controller. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) { controller, cancelled, error, result in + + // Completion handler to process the result. + // The `cancelled` parameter indicates if the cancel button was tapped. + + controller.presentingViewController?.dismiss(animated: true) + } + } +} diff --git a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift new file mode 100644 index 0000000..c005b23 --- /dev/null +++ b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift @@ -0,0 +1,55 @@ +// +// BarcodeViewFinderUI2ViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeViewFinderUI2ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Start scanning here. Usually this is an action triggered by some button or menu. + self.startScanning() + } + + func startScanning() { + + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Set visibility for the view finder. + configuration.viewFinder.visible = true + + // Create the instance of the style, either `SBSDKUI2FinderCorneredStyle` or `SBSDKUI2FinderStrokedStyle`. + let style = SBSDKUI2FinderCorneredStyle(strokeColor: SBSDKUI2Color(colorString: "#FFFFFFFF"), + strokeWidth: 3.0, + cornerRadius: 10.0) + + // Set the configured style. + configuration.viewFinder.style = style + + // Set the desired aspect ratio of the view finder. + configuration.viewFinder.aspectRatio = SBSDKAspectRatio(width: 1.0, height: 1.0) + + // Set the overlay color. + configuration.viewFinder.overlayColor = SBSDKUI2Color(colorString: "#26000000") + + // Create and set an array of accepted barcode formats. + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) + + // Present the view controller modally. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) { controller, cancelled, error, result in + + // Completion handler to process the result. + // The `cancelled` parameter indicates if the cancel button was tapped. + + controller.presentingViewController?.dismiss(animated: true) + } + } +} diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift new file mode 100644 index 0000000..dba34a8 --- /dev/null +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift @@ -0,0 +1,70 @@ +// +// BarcodeHandlingResultViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeHandlingResultViewController: UIViewController { + + // The instance of the scanner view controller. + var scannerViewController: SBSDKBarcodeScannerViewController! + + override func viewDidLoad() { + super.viewDidLoad() + + // Create the `SBSDKBarcodeScannerViewController` instance. + self.scannerViewController = SBSDKBarcodeScannerViewController(parentViewController: self, + parentView: self.view, + configuration: .init(), + delegate: self) + } +} + +extension BarcodeHandlingResultViewController: SBSDKBarcodeScannerViewControllerDelegate { + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didScanBarcodes codes: [SBSDKBarcodeItem]) { + + // Process result + codes.forEach({ barcode in + + print("Barcode Identity String: \(barcode.identityString)") + print("Barcode Text: \(barcode.text)") + print("Barcode Text with Extension: \(barcode.textWithExtension)") + print("Barcode Format: \(barcode.format)") + + // Retrieve the extracted (known) document. + // e.g Boarding Pass + if let boardingPass = SBSDKBarcodeDocumentModelBoardingPass(document: barcode.extractedDocument) { + + if let passengerName = boardingPass.passengerName { + print("Passenger name: \(passengerName)") + } + print("Number of legs: \(boardingPass.legs)") + + boardingPass.legs.forEach({ (leg) in + print("Flight number: \(leg.flightNumber?.value?.text ?? "")") + print("Seat number: \(leg.seatNumber?.value?.text ?? "")") + print("Date of flight julian: \(leg.dateOfFlightJulian?.value?.text ?? "")") + print("Departure Airport code: \(leg.departureAirportCode?.value?.text ?? "")") + print("Destination Airport code: \(leg.destinationAirportCode?.value?.text ?? "")") + + // or print all fields. + leg.document.fields.forEach({ field in + print("\n" + "\(field.type.displayText ?? ""): \(field.value?.text ?? "")") + }) + }) + + // or print all fields. + boardingPass.document.fields.forEach({ field in + print("\n" + "\(field.type.displayText ?? ""): \(field.value?.text ?? "")") + }) + } + + }) + } +} diff --git a/Documentation Code Snippets/General Scanner Configuration/BarcodeGeneralConfiguration.swift b/Documentation Code Snippets/General Scanner Configuration/BarcodeGeneralConfiguration.swift new file mode 100644 index 0000000..0ce52ab --- /dev/null +++ b/Documentation Code Snippets/General Scanner Configuration/BarcodeGeneralConfiguration.swift @@ -0,0 +1,130 @@ +// +// BarcodeGeneralConfiguration.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeGeneralConfiguration { + + func configIndividualSymbology() { + + // The barcode formats to be scanned. + let formatsToDetect = [SBSDKBarcodeFormat.qrCode, SBSDKBarcodeFormat.aztec, SBSDKBarcodeFormat.code11] + + // Create an instance of `SBSDKBarcodeFormatCommonConfiguration`. + let formatConfiguration = SBSDKBarcodeFormatCommonConfiguration(formats: formatsToDetect) + + // Create an instance of `SBSDKBarcodeScannerConfiguration`. + let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: [formatConfiguration]) + } + + func configIndividualSymbologyAdvance() { + + // Create qrCode format configuration. + let qrCodeFormatConfiguration = SBSDKBarcodeFormatQRCodeConfiguration( + regexFilter: "", + minimumSizeScore: 10, + addAdditionalQuietZone: false, + gs1Handling: .parse, + strictMode: true, + qr: true, + microQr: false, + rmqr: false + ) + + // Create code11 format configuration. + let code11FormatConfiguration = SBSDKBarcodeFormatCode11Configuration( + regexFilter: "", + minimumSizeScore: 10, + addAdditionalQuietZone: false, + minimum1DQuietZoneSize: 6, + stripCheckDigits: false, + minimumTextLength: 1, maximumTextLength: 0, + checksum: true + ) + + // Create an array of all the desired format configurations. + let detectionFormatConfigurations = [qrCodeFormatConfiguration, code11FormatConfiguration] + + // Create an instance of `SBSDKBarcodeScannerConfiguration`. + let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: detectionFormatConfigurations) + } + + func configGroupedSymbology() { + + // The barcode formats to be scanned. + + // Common + var formatsToDetect: [SBSDKBarcodeFormat] + + // Common barcodes. + formatsToDetect = SBSDKBarcodeFormats.common + + // One-D barcodes. + formatsToDetect = SBSDKBarcodeFormats.oned + + // Two-D barcodes. + formatsToDetect = SBSDKBarcodeFormats.twod + + // Postal barcodes. + formatsToDetect = SBSDKBarcodeFormats.postal + + // Pharma barcodes. + formatsToDetect = SBSDKBarcodeFormats.pharma + + // All barcode formats + formatsToDetect = SBSDKBarcodeFormats.all + + // Create an instance of `SBSDKBarcodeFormatCommonConfiguration`. + let formatConfiguration = SBSDKBarcodeFormatCommonConfiguration(formats: formatsToDetect) + + // Create an instance of `SBSDKBarcodeScannerConfiguration`. + let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: [formatConfiguration]) + } + + func configDocumentParsers() { + + // List of barcode document formats to extract. + let documentFormats: [SBSDKBarcodeDocumentFormat] = [.gs1, .boardingPass, .swissQr] + + do { + // Instantiate the parser, providing the list of formats. + let parser = try SBSDKBarcodeDocumentParser(acceptedFormats: documentFormats) + + // Some raw barcode string. + let rawBarcodeString = "(01)02804086001986(3103)000220(15)220724(30)01(3922)00198" + + // Run the parser and handle the result. + let document = try parser.parse(rawString: rawBarcodeString) + } + catch { + print("Error running barcode document parser: \(error.localizedDescription)") + } + } + + func configRegularExpression() { + + // Configure the regex. + // You can use `SBSDKBarcodeFormatCommonConfiguration` to create common barcode configuration which + // provides a convenient way to configure common configurations for all desired formats. + let commonConfiguration = SBSDKBarcodeFormatCommonConfiguration( + regexFilter: "\\b[0-5]+\\b", + minimumSizeScore: 0.0, + addAdditionalQuietZone: false, + minimum1DQuietZoneSize: 6, + stripCheckDigits: false, + minimumTextLength: 1, + maximumTextLength: 0, + gs1Handling: .parse, + strictMode: true, + formats: SBSDKBarcodeFormats.common // Set the desired barcodes formats to detect. + ) + + // Create an instance of `SBSDKBarcodeScannerConfiguration`. + let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: [commonConfiguration]) + } +} diff --git a/Documentation Code Snippets/Result Handling/Image/BarcodeImageResultHandlingViewController.swift b/Documentation Code Snippets/Result Handling/Image/BarcodeImageResultHandlingViewController.swift new file mode 100644 index 0000000..e0c592a --- /dev/null +++ b/Documentation Code Snippets/Result Handling/Image/BarcodeImageResultHandlingViewController.swift @@ -0,0 +1,76 @@ +// +// BarcodeImageResultHandlingViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeImageResultHandlingViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // The barcode formats to be scanned. + let formatsToDetect = SBSDKBarcodeFormats.common + + // Create an instance of `SBSDKBarcodeFormatCommonConfiguration`. + let formatConfiguration = SBSDKBarcodeFormatCommonConfiguration(formats: formatsToDetect) + + // Create an instance of `SBSDKBarcodeScannerConfiguration`. + let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: [formatConfiguration]) + + // Configure the scanner to return barcode image. + configuration.returnBarcodeImage = true + + do { + // Create the scanner instance. + let scanner = try SBSDKBarcodeScanner() + + let image = UIImage(named: "test_image")! + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run the scanner passing the image. + let result = try scanner.run(image: imageRef) + + // Handle the result. + result.barcodes.forEach({ barcode in + handle(barcode: barcode) + }) + } + catch { + print("Error running barcode scanner: \(error.localizedDescription)") + } + } + + // Handle the resulting barcode item's image. + func handle(barcode: SBSDKBarcodeItem) { + + // Make sure to set `returnBarcodeImage` to true in `SBSDKBarcodeScannerConfiguration` when setting up the scanner. + + // Retrieve the barcode image. + let image = barcode.sourceImage + + // Since the image is of type `SBSDKImageRef`, it provides some useful operations. + // e.g + + do { + // Convert to UIImage. + let uiImage = try image?.toUIImage() + + // Information about the stored image. + let info = try image?.info() + + // Save the image. + try image?.saveImage(path: "", + options: SBSDKSaveImageOptions(quality: 70, encryptionMode: .disabled)) + } + catch { + print("Error handling barcode image: \(error.localizedDescription)") + } + } +} diff --git a/Documentation Code Snippets/Result Handling/Raw values/BarcodeRawResultHandlingViewController.swift b/Documentation Code Snippets/Result Handling/Raw values/BarcodeRawResultHandlingViewController.swift new file mode 100644 index 0000000..d57d7c5 --- /dev/null +++ b/Documentation Code Snippets/Result Handling/Raw values/BarcodeRawResultHandlingViewController.swift @@ -0,0 +1,80 @@ +// +// BarcodeRawResultHandlingViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 15.07.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeRawResultHandlingViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + do { + // Create the scanner instance. + let scanner = try SBSDKBarcodeScanner() + + let image = UIImage(named: "test_image")! + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run the scanner passing the image. + let result = try scanner.run(image: imageRef) + + // Handle the result. + result.barcodes.forEach({ barcode in + handle(barcode: barcode) + }) + } + catch { + print("Error running barcode scanner: \(error.localizedDescription)") + } + } + + // Handle the resulting barcode item and it's raw values. + func handle(barcode: SBSDKBarcodeItem) { + + // Retrieve raw text + print("Raw text: \(barcode.text)") + + // Raw text with extension + print("Raw text with extension: \(barcode.textWithExtension)") + + // Some barcode formats are able to encode binary data. If a barcode contains binary data, it's provided as a list + // of bytes in the rawBytes field. + print("Raw bytes: \(barcode.rawBytes)") + + // Encoding information for the rawBytes field. Each element of this list covers some portion of the rawBytes array. + print("Raw byte encodings: \(barcode.rawBytesEncodings)") + + // True if this is a 1D barcode that is printed upside-down, that is, the barcode was scanned right-to-left. + print("Is Upside Down: \(barcode.isUpsideDown)") + + // The size score is a floating point value between 0 and 1 that represents the relative size of the barcode in the + // input image. + // Barcodes taking up a small portion of the input image will have a score close to 0, while barcodes that take a + // large portion will have a score close to 1. + print("Size Score: \(barcode.sizeScore)") + + // The index of the barcode to uniquely identify it. + // In case of frame accumulation, the index remains the same across frames. + print("Global index: \(barcode.globalIndex)") + + // Following properties are helpful to determine the position of the scanned barcode in the input image. + print("Quad: \(barcode.quad)") + print("Quad Normalized: \(barcode.quadNormalized)") + print("Extended Quad: \(barcode.extendedQuad)") + print("Extended Quad Normalized: \(barcode.extendedQuadNormalized)") + + // Also some use case specific properties. Please do read the inline documentation of these properties to not + // miss some important details about different behavior depending on the configuration provided to the scanner. + print("upcEanExtension: \(barcode.upcEanExtension)") + print("isGS1Message: \(barcode.isGS1Message)") + print("isGS1CompositePart: \(barcode.isGS1CompositePart)") + print("dataBarStackSize: \(barcode.dataBarStackSize)") + } +} From 57cd845446d5c491542c425f2b5f483b3019c39b Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Thu, 23 Oct 2025 11:16:51 +0200 Subject: [PATCH 05/17] update code snippets --- ...UIGeneralConfigurationViewController.swift | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift new file mode 100644 index 0000000..d4e6350 --- /dev/null +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift @@ -0,0 +1,116 @@ +// +// BarcodeClassicUIGeneralConfigurationViewController.swift +// ScanbotSDK Examples +// +// Created by Sebastian Husche on 11.11.24. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class BarcodeClassicUIGeneralConfigurationViewController: UIViewController { + + // The instance of the ClassicUI scanner view controller. + var scannerViewController: SBSDKBarcodeScannerViewController! + + override func viewDidLoad() { + super.viewDidLoad() + + // Create the scanner view controller instance. + self.scannerViewController = SBSDKBarcodeScannerViewController(parentViewController: self, + parentView: self.view, + configuration: .init(), + delegate: self) + + // Now you can configure some general properties using one of the configuration objects. + // + // As demonstrated in the functions below there are 3 steps: + // 1. Read the current configuration from the scanner view controller. + // 2. Modify the configuration to your needs. + // 3. Pass the modified configuration back to the scanner view controller to apply it. + + self.applyGeneralConfiguration() + self.applyZoomConfiguration() + self.applyEnergyConfiguration() + self.applyViewFinderConfiguration() + } + + func applyGeneralConfiguration() { + + // The general configuration lets you control timings, video settings and behaviour etc. + + // Read the current general configuration from the scanner view controller. + let generalConfiguration = self.scannerViewController.generalConfiguration + + // Modify it to your needs. + generalConfiguration.minimumTimeWithoutDeviceMotionBeforeDetection = 0.5 + // To keep session alive until deallocated. + generalConfiguration.cameraSessionKeepAliveTimeout = TimeInterval.greatestFiniteMagnitude + + // After changing the configuration you need to pass it back to the scanner view controller in order to apply it. + self.scannerViewController.generalConfiguration = generalConfiguration + } + + func applyZoomConfiguration() { + + // The zoom configuration lets you control the zooming behaviour of the scanner view controller, e.g. + // if zooming is enabled, the zoom range, the initial zoom factor, discrete zoom steps and zoom related gestures. + + // Read the current zoom configuration from the scanner view controller. + let zoomConfiguration = scannerViewController.zoomConfiguration + + // Modify it to your needs. + zoomConfiguration.isZoomingEnabled = true + zoomConfiguration.zoomRange = SBSDKZoomRange(minZoom: 1.0, maxZoom: 12.0) + zoomConfiguration.initialZoomFactor = 2.0 + zoomConfiguration.isPinchToZoomEnabled = true + + // After changing the configuration you need to pass it back to the scanner view controller in order to apply it. + self.scannerViewController.zoomConfiguration = zoomConfiguration + } + + func applyEnergyConfiguration() { + + // The energy configuration lets you control the energy consumption of the scanner view controller, e.g. by + // turning the energy-safe-mode on or off, changing the detection rates and the inactivity timeout. + + // Read the current energy configuration from the scanner view controller. + let energyConfiguration = scannerViewController.energyConfiguration + + // Modify it to your needs. + energyConfiguration.inactivityTimeout = 10.0 + energyConfiguration.detectionRate = 60 + energyConfiguration.energySaveDetectionRate = 5 + + // After changing the configuration you need to pass it back to the scanner view controller in order to apply it. + self.scannerViewController.energyConfiguration = energyConfiguration + } + + func applyViewFinderConfiguration() { + + // The view finder configuration lets you control the appearance of the view finder, + // e.g. if it is enabled, its aspect ratio, its colors and style, its offsets and insets and more. + + // Read the current view finder configuration from the scanner view controller. + let viewFinderConfiguration = scannerViewController.viewFinderConfiguration + + // Modify it to your needs. + viewFinderConfiguration.isViewFinderEnabled = true + viewFinderConfiguration.aspectRatio = SBSDKAspectRatio(width: 8.0, height: 5.0) + viewFinderConfiguration.lineColor = UIColor.white.withAlphaComponent(0.85) + + // After changing the configuration you need to pass it back to the scanner view controller in order to apply it. + self.scannerViewController.viewFinderConfiguration = viewFinderConfiguration + } + +} + +extension BarcodeClassicUIGeneralConfigurationViewController: SBSDKBarcodeScannerViewControllerDelegate { + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didScanBarcodes codes: [SBSDKBarcodeItem]) { + + // Handle scanned barcodes. + } +} + From f877ff57ef8a9a8313000015d586644550f904ce Mon Sep 17 00:00:00 2001 From: Seifeddine Bouzid Date: Fri, 24 Oct 2025 11:28:39 +0200 Subject: [PATCH 06/17] update to sdk v.8 --- Podfile | 2 +- .../ClassicBarcodeScanner.swift | 2 +- .../ClassicBatchBarcodeScanner.swift | 2 +- .../ScanAndCountResultsViewController.swift | 2 +- .../StartingViewController.swift | 43 +++++++++++-------- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Podfile b/Podfile index 7068db3..8110902 100644 --- a/Podfile +++ b/Podfile @@ -3,5 +3,5 @@ platform :ios, '13.0' target 'ScanbotBarcodeScannerSDKDemo' do use_frameworks! - pod 'ScanbotBarcodeScannerSDK', '7.1.0' + pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC1' end diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift index b91b89f..22ec1e3 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift @@ -48,7 +48,7 @@ class ClassicBarcodeScanner: UIViewController { return BarcodeResult(type: barcode.format, rawTextString: barcode.text, rawTextStringWithExtension: barcode.textWithExtension, - barcodeImage: barcode.sourceImage?.toUIImage(), + barcodeImage: try? barcode.sourceImage?.toUIImage(), rawBytes: barcode.rawBytes, formattedDocument: barcode.extractedDocument) }) diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift index 41cfc8b..c4fc172 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift @@ -106,7 +106,7 @@ extension ClassicBatchBarcodeScanner: UITableViewDataSource, UITableViewDelegate let cell = tableView.dequeueReusableCell(withIdentifier: "barcodeCell") as! ClassicBatchBarcodeScannerTableCell let code = self.scannedBarcodes[indexPath.row] - cell.barcodeImageView.image = code.sourceImage?.toUIImage() + cell.barcodeImageView.image = try? code.sourceImage?.toUIImage() cell.barcodeLabel.text = code.textWithExtension cell.barcodeTypeLabel.text = code.format.name return cell diff --git a/ScanbotBarcodeScannerSDKDemo/ScanAndCountResultsViewController.swift b/ScanbotBarcodeScannerSDKDemo/ScanAndCountResultsViewController.swift index 0f217b8..ca1e0d9 100644 --- a/ScanbotBarcodeScannerSDKDemo/ScanAndCountResultsViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/ScanAndCountResultsViewController.swift @@ -29,7 +29,7 @@ class ScanAndCountResultsViewController: UIViewController { destination.barcode = BarcodeResult(type: selectedBarcode.format, rawTextString: selectedBarcode.text, rawTextStringWithExtension: selectedBarcode.textWithExtension, - barcodeImage: selectedBarcode.sourceImage?.toUIImage(), + barcodeImage: try? selectedBarcode.sourceImage?.toUIImage(), rawBytes: selectedBarcode.rawBytes, formattedDocument: selectedBarcode.extractedDocument) } diff --git a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift index 5761204..1ddb1c8 100644 --- a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift @@ -50,8 +50,8 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all - + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) + let usecase = SBSDKUI2SingleScanningMode() usecase.confirmationSheetEnabled = true usecase.barcodeInfoMapping.barcodeItemMapper = self @@ -83,7 +83,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2SingleScanningMode() usecase.confirmationSheetEnabled = true @@ -116,7 +116,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2SingleScanningMode() usecase.confirmationSheetEnabled = true @@ -148,7 +148,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2MultipleScanningMode() usecase.mode = .unique @@ -180,7 +180,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2MultipleScanningMode() usecase.mode = .unique @@ -213,7 +213,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2MultipleScanningMode() usecase.mode = .counting @@ -249,7 +249,7 @@ class StartingViewController: UITableViewController { self.detectedBarcodes = [] let config = SBSDKUI2BarcodeScannerScreenConfiguration() - config.scannerConfiguration.barcodeFormats = SBSDKBarcodeFormats.all + config.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.all) let usecase = SBSDKUI2MultipleScanningMode() usecase.mode = .counting @@ -315,21 +315,25 @@ class StartingViewController: UITableViewController { } } - private func detectBarcodesOnImage(_ image: UIImage) { + private func detectBarcodesOnImage(_ image: SBSDKImageRef) { detectedBarcodes.removeAll() let barcodeConfiguration = SBSDKBarcodeFormatCommonConfiguration(formats: Array(SharedParameters.acceptedBarcodeTypes)) let configuration = SBSDKBarcodeScannerConfiguration(barcodeFormatConfigurations: [barcodeConfiguration]) - let scanner = SBSDKBarcodeScanner(configuration: configuration) - let result = scanner.scan(from: image) - result?.barcodes.forEach({ barcode in - let barcodeResult = BarcodeResult(type: barcode.format, - rawTextString: barcode.text, - rawTextStringWithExtension: barcode.textWithExtension) - detectedBarcodes.append(barcodeResult) - }) - self.barcodeImage = nil + do { + let scanner = try SBSDKBarcodeScanner(configuration: configuration) + let result = try scanner.run(image: image) + result.barcodes.forEach({ barcode in + let barcodeResult = BarcodeResult(type: barcode.format, + rawTextString: barcode.text, + rawTextStringWithExtension: barcode.textWithExtension) + detectedBarcodes.append(barcodeResult) + }) + self.barcodeImage = nil + } catch { + print("Error during barcode scanning: \(error)") + } } private func showImagePicker() { @@ -420,7 +424,8 @@ extension StartingViewController: UINavigationControllerDelegate, UIImagePickerC didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { self.dismiss(animated: true) { - self.detectBarcodesOnImage(image) + let imageRef = SBSDKImageRef.fromUIImage(image: image) + self.detectBarcodesOnImage(imageRef) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) } } From e7aa11d375a11a787ae7736fd924f552945da92e Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Wed, 12 Nov 2025 14:05:44 +0500 Subject: [PATCH 07/17] update code snippets --- ...tipleBarcodeScannerUI2ViewController.swift | 7 +-- ...CountBarcodeScannerUI2ViewController.swift | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift index f0a1a34..af0aad8 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift @@ -25,11 +25,8 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { // Initialize the multi scan usecase. let multiUsecase = SBSDKUI2MultipleScanningMode() - // Set the counting repeat delay. - multiUsecase.countingRepeatDelay = 1000 - - // Set the counting mode. - multiUsecase.mode = .counting + // Set the unique mode. + multiUsecase.mode = .unique // Set the sheet mode of the barcodes preview. multiUsecase.sheet.mode = .collapsedSheet diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift new file mode 100644 index 0000000..88b9d08 --- /dev/null +++ b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift @@ -0,0 +1,63 @@ +// +// ScanAndCountBarcodeScannerUI2ViewController.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 11.11.25. +// + +import Foundation +import ScanbotBarcodeScannerSDK + +class ScanAndCountBarcodeScannerUI2ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Start scanning here. Usually this is an action triggered by some button or menu. + self.startScanning() + } + + func startScanning() { + + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Initialize the multi scan usecase. + let multiUsecase = SBSDKUI2MultipleScanningMode() + + // Set the counting repeat delay. + multiUsecase.countingRepeatDelay = 1000 + + // Set the counting mode. + multiUsecase.mode = .counting + + // Set the sheet mode of the barcodes preview. + multiUsecase.sheet.mode = .collapsedSheet + + // Set the height of the collapsed sheet. + multiUsecase.sheet.collapsedVisibleHeight = .large + + // Enable manual count change. + multiUsecase.sheetContent.manualCountChangeEnabled = true + + // Configure the submit button. + multiUsecase.sheetContent.submitButton.text = "Submit" + multiUsecase.sheetContent.submitButton.foreground.color = SBSDKUI2Color(colorString: "#000000") + + // Set the configured usecase. + configuration.useCase = multiUsecase + + // Create and set an array of accepted barcode formats. + configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) + + // Present the view controller modally. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) { controller, cancelled, error, result in + + // Completion handler to process the result. + // The `cancelled` parameter indicates if the cancel button was tapped. + + controller.presentingViewController?.dismiss(animated: true) + } + } +} From 2ab2aa94a1799e9697dbe4156aa2adf0ab8f5158 Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Mon, 17 Nov 2025 17:04:37 +0500 Subject: [PATCH 08/17] update code snippets --- ...erlayBarcodeScannerUI2ViewController.swift | 13 +++++++--- ...ionBarConfigurationUI2ViewController.swift | 13 +++++++--- ...dPickBarcodeScannerUI2ViewController.swift | 13 +++++++--- ...rcodeGettingStartedUI2ViewController.swift | 25 +++++++++++-------- ...ppingBarcodeScannerUI2ViewController.swift | 13 +++++++--- ...BarcodeLocalizationUI2ViewController.swift | 13 +++++++--- ...tipleBarcodeScannerUI2ViewController.swift | 13 +++++++--- .../BarcodePaletteUI2ViewController.swift | 13 +++++++--- .../BarcodesSheetModeUI2ViewController.swift | 13 +++++++--- ...CountBarcodeScannerUI2ViewController.swift | 13 +++++++--- ...ingleBarcodeScannerUI2ViewController.swift | 13 +++++++--- .../SwiftUI/BarcodeScannerSwiftUIView.swift | 19 ++++++++------ .../TinyBarcodeScannerUI2ViewController.swift | 15 ++++++++--- .../TopBarBarcodeUI2ViewController.swift | 13 +++++++--- ...BarcodeUserGuidanceUI2ViewController.swift | 13 +++++++--- .../BarcodeViewFinderUI2ViewController.swift | 13 +++++++--- .../BarcodeScanAndCountViewController.swift | 6 +++++ ...UIGeneralConfigurationViewController.swift | 6 +++++ .../BarcodeScannerViewController.swift | 6 +++++ .../BarcodeHandlingResultViewController.swift | 7 ++++++ .../BarcodesBatchViewController.swift | 6 +++++ .../BarcodeDataParserViewController.swift | 6 +++++ 22 files changed, 204 insertions(+), 61 deletions(-) diff --git a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift index ba912f1..97714a4 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift @@ -40,12 +40,19 @@ class AROverlayBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift index 7a2f404..85407f3 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift @@ -55,12 +55,19 @@ class ActionBarConfigurationUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift index 39fe39c..5f8fe9b 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift @@ -54,12 +54,19 @@ class FindAndPickBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift index b3e7fcc..c79d740 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift @@ -15,14 +15,20 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() - // Present the scanner view controller modally on this view controller. + // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + print("Error scanning barcode: \(error.localizedDescription)") + } } } @@ -33,12 +39,12 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { // Present the scanner view controller modally on this view controller. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in - if cancelled { - - // Indicates that the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") } else if let items = result?.items { @@ -78,7 +84,6 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { print("\n" + "\(field.type.displayText ?? ""): \(field.value?.text ?? "")") }) } - }) } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift index 3b1b06d..22632c6 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift @@ -63,12 +63,19 @@ class InfoMappingBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift index c54ab40..f78d22f 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift @@ -33,12 +33,19 @@ class BarcodeLocalizationUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift index af0aad8..0da48c5 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift @@ -49,12 +49,19 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift index 6a1543c..809cc4a 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift @@ -52,12 +52,19 @@ class BarcodePaletteUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift index d565a5b..df3c0a3 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift @@ -43,12 +43,19 @@ class BarcodesSheetModeUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift index 88b9d08..ae9c016 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift @@ -52,12 +52,19 @@ class ScanAndCountBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift index 2d8990f..353e828 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift @@ -58,12 +58,19 @@ class SingleBarcodeScannerUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift b/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift index c4928e4..10a0001 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/SwiftUI/BarcodeScannerSwiftUIView.swift @@ -10,9 +10,6 @@ import ScanbotBarcodeScannerSDK struct BarcodeScannerSwiftUIView: View { - // A boolean state variable indicating whether the barcode scanner interface should be presented. - @State var showScan: Bool = false - // An instance of `SBSDKUI2BarcodeScannerScreenConfiguration` which contains the configuration settings for the barcode scanner. let configuration: SBSDKUI2BarcodeScannerScreenConfiguration = { @@ -63,18 +60,24 @@ struct BarcodeScannerSwiftUIView: View { @State var scannerResult: SBSDKUI2BarcodeScannerUIResult? var body: some View { - if let scannerResult = self.scannerResult { + + if let scannerResult { + // Process and show the results here. + Text("Barcodes scanned: \(scannerResult.items.count)") - } else if let error = self.scanError { + } else if let scanError { + // Show error view here. + Text("Scan error: \(scanError.localizedDescription)") } else { // Show the scanner, pass the configuration and the button and error handlers. SBSDKUI2BarcodeScannerView(configuration: configuration, - onSubmit: { result in scannerResult = result }, - onCancel: { /* Dismiss your view here. */ }, - onError: { error in scanError = error }) + completion: { result, error in + scannerResult = result + scanError = error + }) .ignoresSafeArea() } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift index c34ba36..6146a1e 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift @@ -25,14 +25,21 @@ class TinyBarcodeScannerUI2ViewController: UIViewController { // Enable locking the focus at the minimum possible distance. configuration.cameraConfiguration.minFocusDistanceLock = true - // Present the scanner view controller modally on this view controller. + // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift index 4e78331..115bbcd 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift @@ -40,12 +40,19 @@ class TopBarBarcodeUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift index 20a66f7..b509a3f 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift @@ -40,12 +40,19 @@ class BarcodeUserGuidanceUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift index c005b23..bdd75a9 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift @@ -44,12 +44,19 @@ class BarcodeViewFinderUI2ViewController: UIViewController { // Present the view controller modally. SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, cancelled, error, result in + configuration: configuration) { controller, result, error in // Completion handler to process the result. - // The `cancelled` parameter indicates if the cancel button was tapped. - controller.presentingViewController?.dismiss(animated: true) + if let result { + + // Process the result. + + } else if let error { + + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift index 7dbfe56..8916175 100644 --- a/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift +++ b/Documentation Code Snippets/Barcode ScanAndCount Scanner/BarcodeScanAndCountViewController.swift @@ -82,4 +82,10 @@ extension BarcodeScanAndCountViewController: SBSDKBarcodeScanAndCountViewControl // Provide a custom overlay view for the barcode return UIImageView(image: UIImage(named: "")) } + + func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift index d4e6350..368217c 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeClassicUIGeneralConfigurationViewController.swift @@ -112,5 +112,11 @@ extension BarcodeClassicUIGeneralConfigurationViewController: SBSDKBarcodeScanne // Handle scanned barcodes. } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift index 0f57a15..99efaf9 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Classic/BarcodeScannerViewController.swift @@ -88,4 +88,10 @@ extension BarcodeScannerViewController: SBSDKBarcodeScannerViewControllerDelegat func barcodeScannerControllerShouldScanBarcodes(_ controller: SBSDKBarcodeScannerViewController) -> Bool { return self.shouldDetectBarcodes } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } diff --git a/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift b/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift index dba34a8..556e5a8 100644 --- a/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift +++ b/Documentation Code Snippets/Barcode and QR-Code Scanner/Handle result/BarcodeHandlingResultViewController.swift @@ -26,6 +26,13 @@ class BarcodeHandlingResultViewController: UIViewController { extension BarcodeHandlingResultViewController: SBSDKBarcodeScannerViewControllerDelegate { + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, didScanBarcodes codes: [SBSDKBarcodeItem]) { diff --git a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift index 44d1573..060f683 100644 --- a/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift +++ b/Documentation Code Snippets/BarcodesBatchScanner/BarcodesBatchViewController.swift @@ -87,4 +87,10 @@ extension BarcodesBatchViewController: SBSDKBarcodeScannerViewControllerDelegate func barcodeScannerControllerShouldScanBarcodes(_ controller: SBSDKBarcodeScannerViewController) -> Bool { return self.shouldDetectBarcodes } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } diff --git a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift index 90bd3ec..4992756 100644 --- a/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift +++ b/Documentation Code Snippets/Data Parser/BarcodeDataParserViewController.swift @@ -101,4 +101,10 @@ extension BarcodeDataParserViewController: SBSDKBarcodeScannerViewControllerDele func barcodeScannerControllerShouldScanBarcodes(_ controller: SBSDKBarcodeScannerViewController) -> Bool { return true } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + print("Error scanning barcode: \(error.localizedDescription)") + } } From 95d94e3a6ac5459b418e0554f0be54152a381a82 Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Thu, 20 Nov 2025 17:42:40 +0500 Subject: [PATCH 09/17] Add general result handling code snipept --- .../BarcodeResultHandlingExamples.swift | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation Code Snippets/Result Handling/General/BarcodeResultHandlingExamples.swift diff --git a/Documentation Code Snippets/Result Handling/General/BarcodeResultHandlingExamples.swift b/Documentation Code Snippets/Result Handling/General/BarcodeResultHandlingExamples.swift new file mode 100644 index 0000000..a3aeeeb --- /dev/null +++ b/Documentation Code Snippets/Result Handling/General/BarcodeResultHandlingExamples.swift @@ -0,0 +1,146 @@ +// +// ResultHandlingExamples.swift +// ScanbotSDK Examples +// +// Created by Rana Sohaib on 19.11.25. +// + +import UIKit +import ScanbotBarcodeScannerSDK + +class BarcodeResultHandlingGeneral { + + func handleError(_ error: Error) { + + print("Error: \(error.localizedDescription)") + + // Cast `Error` to type `SBSDKError` to access underlying SDK properties. + // We can safely assume that only `SBSDKErrors` are thrown + let sdkError = error as! SBSDKError + + // Use switch to determine the error and handle it according to your use case. + switch sdkError { + case .unknownError(let string): return + case .invalidLicense(let string): return + case .nullPointer(let string): return + case .invalidArgument(let string): return + case .invalidImageRef(let string): return + case .componentUnavailable(let string):return + case .illegalState(let string): return + case .ioError(let string): return + case .invalidData(let string): return + case .operationCanceled(let string): return + case .outOfMemory(let string): return + case .timeout(let string): return + default: print("Unknown error code with description: \(sdkError.localizedDescription)") + } + } + + func checkCanceledError(_ error: Error) { + + // We can safely assume that only `SBSDKErrors` are thrown + let sdkError = error as! SBSDKError + + // Check if the error represents a canceled operation. + if sdkError.isCanceled { + print("The operation was cancelled before completion or by the user: \(error.localizedDescription)") + } + } + + func doCatchExample() { + + // The image containing a barcode. + guard let image = UIImage(named: "barcodeImage") else { return } + + do { + // Create an instance of the scanner. + let scanner = try SBSDKBarcodeScanner(configuration: .init()) + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run scanner on the given image. + let result = try scanner.run(image: imageRef) + } + catch { + print("Error scanning barcode: \(error.localizedDescription)") + } + } + + func optionalTryExample() { + + // The image containing a barcode. + guard let image = UIImage(named: "barcodeImage") else { return } + + // Create an instance of the scanner. + let scanner = try? SBSDKBarcodeScanner(configuration: .init()) + + // Create an image ref from UIImage. + let imageRef = SBSDKImageRef.fromUIImage(image: image) + + // Run scanner on the given image. + let result = try? scanner?.run(image: imageRef) + + if let result { + // Handle the result. + + } else { + // Handle failure. + // Note: Here you do not have any information about the error contrary to the `do-catch` + // as the `error` itself is not available. + } + } +} + +// RTU-UI +class BarcodeRTUUIResultHandlingExampleViewController: UIViewController { + + func startScanning() { + + // Present the view controller modally. + SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: .init()) { controller, result, error in + if let error { + + // We can safely assume that only `SBSDKErrors` are thrown. + let sdkError = error as! SBSDKError + + // Check if the error represents a canceled operation. + if sdkError.isCanceled { + print("The operation was cancelled before completion or by the user") + + } else { + print("Error scanning barcodes: \(sdkError.localizedDescription)") + } + + } else if let result { + // Handle the result. + } + } + } +} + +// Classic +class BarcodeClassicResultHandlingExampleViewController: UIViewController, SBSDKBarcodeScannerViewControllerDelegate { + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didScanBarcodes codes: [SBSDKBarcodeItem]) { + // Handle the result. + } + + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, + didFailScanning error: any Error) { + // Handle the error. + + // We can safely assume that only `SBSDKErrors` are thrown. + let sdkError = error as! SBSDKError + + // Check if the error represents a canceled operation. + if sdkError.isCanceled { + print("The operation was cancelled before completion or by the user") + + } else { + print("Error scanning barcodes: \(sdkError.localizedDescription)") + } + } +} From 74a8ea26bd35b6c704fd7ddcf8af2dfb7d6a78c6 Mon Sep 17 00:00:00 2001 From: atacand1920 Date: Fri, 21 Nov 2025 14:34:23 +0100 Subject: [PATCH 10/17] update to RC5 --- Podfile | 2 +- .../ClassicBarcodeScanner.swift | 10 ++++ .../ClassicBatchBarcodeScanner.swift | 9 ++++ .../ScanAndCountViewController.swift | 9 ++++ .../StartingViewController.swift | 48 +++++++++---------- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Podfile b/Podfile index 8110902..2abd325 100644 --- a/Podfile +++ b/Podfile @@ -3,5 +3,5 @@ platform :ios, '13.0' target 'ScanbotBarcodeScannerSDKDemo' do use_frameworks! - pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC1' + pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC5' end diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift index 22ec1e3..ef55534 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift @@ -67,6 +67,16 @@ class ClassicBarcodeScanner: UIViewController { } extension ClassicBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate { + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, didFailScanning error: any Error) { + if let error = error as? SBSDKError { + if error.isCanceled { + print("Scanning was cancelled by the user") + } else { + print(error.localizedDescription) + } + } + } + func barcodeScannerControllerShouldScanBarcodes(_ controller: SBSDKBarcodeScannerViewController) -> Bool { return self.shouldScanBarcodes } diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift index c4fc172..94284bf 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift @@ -72,6 +72,15 @@ extension ClassicBatchBarcodeScanner: SBSDKBarcodeTrackingOverlayControllerDeleg } extension ClassicBatchBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate { + func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, didFailScanning error: any Error) { + if let error = error as? SBSDKError { + if error.isCanceled { + print("Scanning was cancelled by the user") + } else { + print(error.localizedDescription) + } + } + } func barcodeScannerControllerShouldScanBarcodes(_ controller: SBSDKBarcodeScannerViewController) -> Bool { return !self.isScrolling diff --git a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift index 18d1a04..f5f8c85 100644 --- a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift @@ -53,6 +53,15 @@ final class ScanAndCountViewController: UIViewController { } extension ScanAndCountViewController: SBSDKBarcodeScanAndCountViewControllerDelegate { + func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController, didFailScanning error: any Error) { + if let error = error as? SBSDKError { + if error.isCanceled { + print("Scanning was cancelled by the user") + } else { + print(error.localizedDescription) + } + } + } func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController, didScanBarcodes codes: [SBSDKBarcodeItem]) { diff --git a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift index 1ddb1c8..e8f91be 100644 --- a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift @@ -61,9 +61,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -73,7 +73,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -94,9 +94,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -106,7 +106,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -126,9 +126,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -138,7 +138,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -158,9 +158,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -170,7 +170,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -191,9 +191,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -203,7 +203,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -227,9 +227,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -239,7 +239,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -262,9 +262,9 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in + configuration: config) { controller, result, error in - if !cancelled, let items = result?.items { + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -274,7 +274,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } @@ -299,8 +299,8 @@ class StartingViewController: UITableViewController { config.useCase = usecase SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: config) { controller, cancelled, error, result in - if !cancelled, let items = result?.items { + configuration: config) { controller, result, error in + if let items = result?.items { self.detectedBarcodes = items.map({ item in return BarcodeResult(type: item.barcode.format, rawTextString: item.barcode.text, @@ -309,7 +309,7 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else if cancelled { + } else { controller.presentingViewController?.dismiss(animated: true) } } From 20f3e0d3ba57a5ef9eff389c000dc3a530915c1c Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Tue, 25 Nov 2025 16:52:16 +0500 Subject: [PATCH 11/17] update code snippets --- ...erlayBarcodeScannerUI2ViewController.swift | 36 +++++++----- ...ionBarConfigurationUI2ViewController.swift | 36 +++++++----- ...dPickBarcodeScannerUI2ViewController.swift | 36 +++++++----- ...rcodeGettingStartedUI2ViewController.swift | 56 +++++++++---------- ...ppingBarcodeScannerUI2ViewController.swift | 36 +++++++----- ...BarcodeLocalizationUI2ViewController.swift | 36 +++++++----- ...tipleBarcodeScannerUI2ViewController.swift | 36 +++++++----- .../BarcodePaletteUI2ViewController.swift | 36 +++++++----- .../BarcodesSheetModeUI2ViewController.swift | 36 +++++++----- ...CountBarcodeScannerUI2ViewController.swift | 36 +++++++----- ...ingleBarcodeScannerUI2ViewController.swift | 36 +++++++----- .../TinyBarcodeScannerUI2ViewController.swift | 36 +++++++----- .../TopBarBarcodeUI2ViewController.swift | 36 +++++++----- ...BarcodeUserGuidanceUI2ViewController.swift | 36 +++++++----- .../BarcodeViewFinderUI2ViewController.swift | 36 +++++++----- 15 files changed, 336 insertions(+), 224 deletions(-) diff --git a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift index 97714a4..4727d11 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class AROverlayBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -39,20 +41,26 @@ class AROverlayBarcodeScannerUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift index 85407f3..5994e76 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift @@ -14,10 +14,12 @@ class ActionBarConfigurationUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -54,20 +56,26 @@ class ActionBarConfigurationUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift index 5f8fe9b..e989225 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class FindAndPickBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -53,20 +55,26 @@ class FindAndPickBarcodeScannerUI2ViewController: UIViewController { configuration.useCase = usecase // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift index c79d740..6617e2b 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift @@ -12,21 +12,20 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { func launchRTUUIv2Scanner() { - // Create the default configuration object. - let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() - - // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + Task { + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() - if let result { - - // Process the result. - - } else if let error { + // Present the view controller modally. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + } catch { + // Any other error print("Error scanning barcode: \(error.localizedDescription)") } } @@ -34,22 +33,16 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { func handleScanResults() { - // Create the default configuration object. - let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() - - // Present the scanner view controller modally on this view controller. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") - - } else if let items = result?.items { - + Task { + // Create the default configuration object. + let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() + + // Present the view controller modally. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, + configuration: configuration) // Process result - items.forEach({ item in + result.items.forEach({ item in print("Barcode Identity String: \(item.barcode.identityString)") print("Scan count: \(item.count)") @@ -86,6 +79,13 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { } }) } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") + } } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift index 22632c6..3b23311 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class InfoMappingBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -62,20 +64,26 @@ class InfoMappingBarcodeScannerUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift index f78d22f..9e0273f 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift @@ -13,10 +13,12 @@ class BarcodeLocalizationUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -32,20 +34,26 @@ class BarcodeLocalizationUI2ViewController: UIViewController { configuration.localization = localization // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift index 0da48c5..7353bbb 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -48,20 +50,26 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift index 809cc4a..5bc1055 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift @@ -14,10 +14,12 @@ class BarcodePaletteUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -51,20 +53,26 @@ class BarcodePaletteUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift index df3c0a3..a64e18a 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift @@ -14,10 +14,12 @@ class BarcodesSheetModeUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -42,20 +44,26 @@ class BarcodesSheetModeUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift index ae9c016..ff89e22 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class ScanAndCountBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -51,20 +53,26 @@ class ScanAndCountBarcodeScannerUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift index 353e828..0f4895a 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class SingleBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -57,20 +59,26 @@ class SingleBarcodeScannerUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift index 6146a1e..6c3c9be 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift @@ -14,10 +14,12 @@ class TinyBarcodeScannerUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -26,20 +28,26 @@ class TinyBarcodeScannerUI2ViewController: UIViewController { configuration.cameraConfiguration.minFocusDistanceLock = true // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift index 115bbcd..3fac2e4 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift @@ -14,10 +14,12 @@ class TopBarBarcodeUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -39,20 +41,26 @@ class TopBarBarcodeUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift index b509a3f..2672118 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift @@ -14,10 +14,12 @@ class BarcodeUserGuidanceUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -39,20 +41,26 @@ class BarcodeUserGuidanceUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } diff --git a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift index bdd75a9..eb2cffc 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift @@ -14,10 +14,12 @@ class BarcodeViewFinderUI2ViewController: UIViewController { super.viewDidLoad() // Start scanning here. Usually this is an action triggered by some button or menu. - self.startScanning() + Task { + await self.startScanning() + } } - func startScanning() { + func startScanning() async { // Create the default configuration object. let configuration = SBSDKUI2BarcodeScannerScreenConfiguration() @@ -43,20 +45,26 @@ class BarcodeViewFinderUI2ViewController: UIViewController { configuration.scannerConfiguration.setBarcodeFormats(SBSDKBarcodeFormats.twod) // Present the view controller modally. - SBSDKUI2BarcodeScannerViewController.present(on: self, - configuration: configuration) { controller, result, error in - - // Completion handler to process the result. + do { + let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - if let result { - - // Process the result. - - } else if let error { - - // Handle the error. - print("Error scanning barcode: \(error.localizedDescription)") + // Handle the result. + result.items.forEach { barcodeItem in + // e.g + print(barcodeItem.count) + print(barcodeItem.barcode.format.name) + print(barcodeItem.barcode.text) + print(barcodeItem.barcode.textWithExtension) + // Check out other available properties in `SBSDKBarcodeItem`. } + print(result.selectedZoomFactor) + } + catch SBSDKError.operationCanceled { + print("The operation was cancelled before completion or by the user") + + } catch { + // Any other error + print("Error scanning barcode: \(error.localizedDescription)") } } } From f71a0774e846856f47ec2aa42d15c94fb44f943f Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Tue, 25 Nov 2025 22:15:39 +0500 Subject: [PATCH 12/17] update code snippets --- .../AROverlayBarcodeScannerUI2ViewController.swift | 4 ++-- .../ActionBar/ActionBarConfigurationUI2ViewController.swift | 4 ++-- .../FindAndPickBarcodeScannerUI2ViewController.swift | 4 ++-- .../BarcodeGettingStartedUI2ViewController.swift | 5 +++-- .../InfoMappingBarcodeScannerUI2ViewController.swift | 4 ++-- .../Localization/BarcodeLocalizationUI2ViewController.swift | 4 ++-- .../MultipleBarcodeScannerUI2ViewController.swift | 4 ++-- .../Palette/BarcodePaletteUI2ViewController.swift | 4 ++-- .../PreviewMode/BarcodesSheetModeUI2ViewController.swift | 4 ++-- .../ScanAndCountBarcodeScannerUI2ViewController.swift | 4 ++-- .../SingleBarcodeScannerUI2ViewController.swift | 4 ++-- .../Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift | 4 ++-- .../Top Bar/TopBarBarcodeUI2ViewController.swift | 4 ++-- .../User Guidance/BarcodeUserGuidanceUI2ViewController.swift | 4 ++-- .../View Finder/BarcodeViewFinderUI2ViewController.swift | 4 ++-- 15 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift index 4727d11..11c9417 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/AR Overlay/AROverlayBarcodeScannerUI2ViewController.swift @@ -54,8 +54,8 @@ class AROverlayBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift index 5994e76..1656eab 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ActionBar/ActionBarConfigurationUI2ViewController.swift @@ -69,8 +69,8 @@ class ActionBarConfigurationUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift index e989225..ee9b9a5 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/FindAndPick/FindAndPickBarcodeScannerUI2ViewController.swift @@ -68,8 +68,8 @@ class FindAndPickBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift index 6617e2b..463d139 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Getting Started/BarcodeGettingStartedUI2ViewController.swift @@ -20,8 +20,9 @@ class BarcodeGettingStartedUI2ViewController: UIViewController { do { let result = try await SBSDKUI2BarcodeScannerViewController.present(on: self, configuration: configuration) - } - catch SBSDKError.operationCanceled { + // Process the result as needed. + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift index 3b23311..e3bf1db 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/ItemMapper/InfoMappingBarcodeScannerUI2ViewController.swift @@ -77,8 +77,8 @@ class InfoMappingBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift index 9e0273f..5a8bdcc 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Localization/BarcodeLocalizationUI2ViewController.swift @@ -47,8 +47,8 @@ class BarcodeLocalizationUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift index 7353bbb..7908718 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Multiple Scanning/MultipleBarcodeScannerUI2ViewController.swift @@ -63,8 +63,8 @@ class MultipleBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift index 5bc1055..3738917 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Palette/BarcodePaletteUI2ViewController.swift @@ -66,8 +66,8 @@ class BarcodePaletteUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift index a64e18a..a329b35 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/PreviewMode/BarcodesSheetModeUI2ViewController.swift @@ -57,8 +57,8 @@ class BarcodesSheetModeUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift index ff89e22..a7d5e5c 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Scan And Count/ScanAndCountBarcodeScannerUI2ViewController.swift @@ -66,8 +66,8 @@ class ScanAndCountBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift index 0f4895a..620bd51 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Single Scanning/SingleBarcodeScannerUI2ViewController.swift @@ -72,8 +72,8 @@ class SingleBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift index 6c3c9be..10aa502 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Tiny Barcodes/TinyBarcodeScannerUI2ViewController.swift @@ -41,8 +41,8 @@ class TinyBarcodeScannerUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift index 3fac2e4..391a68e 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/Top Bar/TopBarBarcodeUI2ViewController.swift @@ -54,8 +54,8 @@ class TopBarBarcodeUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift index 2672118..c5f56dc 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/User Guidance/BarcodeUserGuidanceUI2ViewController.swift @@ -54,8 +54,8 @@ class BarcodeUserGuidanceUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { diff --git a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift index eb2cffc..10033a5 100644 --- a/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift +++ b/Documentation Code Snippets/Barcode RTUUIV2/View Finder/BarcodeViewFinderUI2ViewController.swift @@ -58,8 +58,8 @@ class BarcodeViewFinderUI2ViewController: UIViewController { // Check out other available properties in `SBSDKBarcodeItem`. } print(result.selectedZoomFactor) - } - catch SBSDKError.operationCanceled { + + } catch SBSDKError.operationCanceled { print("The operation was cancelled before completion or by the user") } catch { From 07cdde2530d2efc2a8fd9eb39febb47e59d49d4f Mon Sep 17 00:00:00 2001 From: Rana Sohaib Date: Wed, 26 Nov 2025 18:33:58 +0500 Subject: [PATCH 13/17] update code snippets --- .../Data Parser/ManualDataParser.swift | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Documentation Code Snippets/Data Parser/ManualDataParser.swift b/Documentation Code Snippets/Data Parser/ManualDataParser.swift index 8bfeb04..5aff9b9 100644 --- a/Documentation Code Snippets/Data Parser/ManualDataParser.swift +++ b/Documentation Code Snippets/Data Parser/ManualDataParser.swift @@ -16,26 +16,26 @@ func parseDataManually() { do { // Instantiate the parser. - let parser = try? SBSDKBarcodeDocumentParser(acceptedFormats: [.gs1]) + let parser = try SBSDKBarcodeDocumentParser(acceptedFormats: [.gs1]) // Run the parser and check the result. - if let document = try? parser?.parse(rawString: rawBarcodeString) { + let document = try parser.parse(rawString: rawBarcodeString) - // Get the parsed document. - guard let parsedDocument = document.parsedDocument else { return } + // Get the parsed document. + guard let parsedDocument = document.parsedDocument else { return } + + // Parse the resulted document as a GS1 document. + if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: parsedDocument) { - // Parse the resulted document as a GS1 document. - if let gs1ParsedDocument = SBSDKBarcodeDocumentModelGS1(document: parsedDocument) { - - // Retrieve the elements. - let elements = gs1ParsedDocument.elements - - // Enumerate over the elements. - for element in elements { - - // Do something with the element. + // Retrieve the elements. + let elements = gs1ParsedDocument.elements + + // Enumerate over the elements. + for element in elements { - print("\(element.dataTitle?.value?.text) = \(element.rawValue?.value?.text)") + // Do something with the element. + if let key = element.dataTitle?.value?.text, let value = element.rawValue?.value?.text { + print("\(key) = \(value)") } } } From d3bdde7ba89266cf97fdd02f0f1e9d4210ebfa2d Mon Sep 17 00:00:00 2001 From: atacand1920 Date: Tue, 9 Dec 2025 12:02:11 +0100 Subject: [PATCH 14/17] Fix license alert #2 --- Podfile | 2 +- .../ClassicBarcodeScanner.swift | 5 +- .../ClassicBatchBarcodeScanner.swift | 5 +- .../ScanAndCountViewController.swift | 5 +- .../StartingViewController.swift | 62 ++++++++++++++++--- 5 files changed, 66 insertions(+), 13 deletions(-) diff --git a/Podfile b/Podfile index 2abd325..5b9f439 100644 --- a/Podfile +++ b/Podfile @@ -3,5 +3,5 @@ platform :ios, '13.0' target 'ScanbotBarcodeScannerSDKDemo' do use_frameworks! - pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC5' + pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC7' end diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift index ef55534..1ce72de 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift @@ -72,7 +72,10 @@ extension ClassicBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate { if error.isCanceled { print("Scanning was cancelled by the user") } else { - print(error.localizedDescription) + sbsdk_showError(error) { [weak self] _ in + guard let self else { return } + self.sbsdk_forceClose(animated: true, completion: nil) + } } } } diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift index 94284bf..92bd3e9 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift @@ -77,7 +77,10 @@ extension ClassicBatchBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate if error.isCanceled { print("Scanning was cancelled by the user") } else { - print(error.localizedDescription) + sbsdk_showError(error) { [weak self] _ in + guard let self else { return } + self.sbsdk_forceClose(animated: true, completion: nil) + } } } } diff --git a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift index f5f8c85..601d5e2 100644 --- a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift @@ -58,7 +58,10 @@ extension ScanAndCountViewController: SBSDKBarcodeScanAndCountViewControllerDele if error.isCanceled { print("Scanning was cancelled by the user") } else { - print(error.localizedDescription) + sbsdk_showError(error) { [weak self] _ in + guard let self else { return } + self.sbsdk_forceClose(animated: true, completion: nil) + } } } } diff --git a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift index e8f91be..b196028 100644 --- a/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/StartingViewController.swift @@ -73,8 +73,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. + controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -106,8 +111,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. + controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -138,8 +148,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. + controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -170,8 +185,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. + controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -203,8 +223,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. + controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -239,8 +264,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. + controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -274,8 +304,13 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. + controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -309,8 +344,14 @@ class StartingViewController: UITableViewController { self.dismiss(animated: true, completion: nil) self.performSegue(withIdentifier: "BarcodeResultList", sender: self) - } else { + + } else if let sdkError = error as? SBSDKError, sdkError.isCanceled { + // Canceled. Do nothing. controller.presentingViewController?.dismiss(animated: true) + } else if let error { + // Show an error alert. + controller.presentingViewController?.dismiss(animated: true) + self.sbsdk_showError(error) } } } @@ -332,7 +373,10 @@ class StartingViewController: UITableViewController { }) self.barcodeImage = nil } catch { - print("Error during barcode scanning: \(error)") + sbsdk_showError(error) { [weak self] _ in + guard let self else { return } + self.sbsdk_forceClose(animated: true, completion: nil) + } } } From a18c4600590495a068605f1acc43f9db83f2215a Mon Sep 17 00:00:00 2001 From: atacand1920 Date: Tue, 16 Dec 2025 14:37:11 +0100 Subject: [PATCH 15/17] Update to RC8 --- Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 5b9f439..7ee7b0f 100644 --- a/Podfile +++ b/Podfile @@ -3,5 +3,5 @@ platform :ios, '13.0' target 'ScanbotBarcodeScannerSDKDemo' do use_frameworks! - pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC7' + pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC8' end From 69ebdcc399dfbe2be4129b26fa9566e331e16f57 Mon Sep 17 00:00:00 2001 From: atacand1920 Date: Wed, 17 Dec 2025 12:29:42 +0100 Subject: [PATCH 16/17] Ensure unique alert & RC9 --- Podfile | 2 +- ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift | 6 +++++- .../ClassicBatchBarcodeScanner.swift | 4 ++++ .../ScanAndCountViewController.swift | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Podfile b/Podfile index 7ee7b0f..8860007 100644 --- a/Podfile +++ b/Podfile @@ -3,5 +3,5 @@ platform :ios, '13.0' target 'ScanbotBarcodeScannerSDKDemo' do use_frameworks! - pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC8' + pod 'ScanbotBarcodeScannerSDK', '8.0.0-RC9' end diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift index 1ce72de..685df35 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBarcodeScanner.swift @@ -14,7 +14,8 @@ class ClassicBarcodeScanner: UIViewController { private var shouldScanBarcodes = true private var scannerController: SBSDKBarcodeScannerViewController! private var selectedBarcode: SBSDKBarcodeScannerResult? - + private var isShowingError: Bool = false + override func viewDidLoad() { super.viewDidLoad() @@ -69,6 +70,9 @@ class ClassicBarcodeScanner: UIViewController { extension ClassicBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate { func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, didFailScanning error: any Error) { if let error = error as? SBSDKError { + guard !isShowingError else { return } + + isShowingError = true if error.isCanceled { print("Scanning was cancelled by the user") } else { diff --git a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift index 92bd3e9..d315855 100644 --- a/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift +++ b/ScanbotBarcodeScannerSDKDemo/ClassicBatchBarcodeScanner.swift @@ -22,6 +22,7 @@ class ClassicBatchBarcodeScanner: UIViewController { private var scannedBarcodes: [SBSDKBarcodeItem] = [] private var scannerController: SBSDKBarcodeScannerViewController! private var isScrolling: Bool = false + private var isShowingError: Bool = false override func viewDidLoad() { super.viewDidLoad() @@ -74,6 +75,9 @@ extension ClassicBatchBarcodeScanner: SBSDKBarcodeTrackingOverlayControllerDeleg extension ClassicBatchBarcodeScanner: SBSDKBarcodeScannerViewControllerDelegate { func barcodeScannerController(_ controller: SBSDKBarcodeScannerViewController, didFailScanning error: any Error) { if let error = error as? SBSDKError { + guard !isShowingError else { return } + + isShowingError = true if error.isCanceled { print("Scanning was cancelled by the user") } else { diff --git a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift index 601d5e2..99f6af8 100644 --- a/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift +++ b/ScanbotBarcodeScannerSDKDemo/ScanAndCountViewController.swift @@ -16,7 +16,8 @@ final class ScanAndCountViewController: UIViewController { private var countedBarcodes = [SBSDKBarcodeScannerAccumulatingResult]() private var scannerController: SBSDKBarcodeScanAndCountViewController! - + private var isShowingError: Bool = false + override func viewDidLoad() { super.viewDidLoad() @@ -55,6 +56,9 @@ final class ScanAndCountViewController: UIViewController { extension ScanAndCountViewController: SBSDKBarcodeScanAndCountViewControllerDelegate { func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController, didFailScanning error: any Error) { if let error = error as? SBSDKError { + guard !isShowingError else { return } + + isShowingError = true if error.isCanceled { print("Scanning was cancelled by the user") } else { From 6a82869a13849b3ea397aae2b657a2e66b1771bf Mon Sep 17 00:00:00 2001 From: atacand1920 Date: Thu, 18 Dec 2025 13:44:43 +0100 Subject: [PATCH 17/17] Fix scan and count result --- ScanbotBarcodeScannerSDKDemo/Main.storyboard | 37 ++++++++++--------- .../ScanAndCountViewController.swift | 3 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ScanbotBarcodeScannerSDKDemo/Main.storyboard b/ScanbotBarcodeScannerSDKDemo/Main.storyboard index 6764f8c..c24502f 100644 --- a/ScanbotBarcodeScannerSDKDemo/Main.storyboard +++ b/ScanbotBarcodeScannerSDKDemo/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -487,7 +487,7 @@ - - + @@ -653,14 +653,14 @@ - + - + - + @@ -701,7 +701,7 @@ - + @@ -743,14 +743,14 @@ - + - +