Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix breaking test due to bugged detectQRCode #86

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions ChronosTests/Token/QrCodeGenerationAndParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,28 +310,40 @@ final class QrCodeGenerationAndParsingTests: XCTestCase {
}

func detectQRCode(in image: UIImage, completion: @escaping (String?) -> Void) {
// Ensure the image has a CGImage representation
guard let cgImage = image.cgImage else {
completion(nil)
return
}

// Configure the request to detect barcodes
let request = VNDetectBarcodesRequest { request, error in
guard error == nil else {
completion(nil)
if let error = error {
print("Barcode detection error: \(error.localizedDescription)")
DispatchQueue.main.async { completion(nil) }
return
}

let results = request.results as? [VNBarcodeObservation]
let payload = results?.first?.payloadStringValue
completion(payload)
// Extract the first payload string if available
if let results = request.results as? [VNBarcodeObservation],
let payload = results.first?.payloadStringValue
{
DispatchQueue.main.async { completion(payload) }
} else {
DispatchQueue.main.async { completion(nil) }
}
}

// Create an image request handler for the given CGImage
let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])

// Perform the request asynchronously
DispatchQueue.global(qos: .userInitiated).async {
do {
try handler.perform([request])
} catch {
completion(nil)
print("Failed to perform barcode detection: \(error.localizedDescription)")
DispatchQueue.main.async { completion(nil) }
}
}
}
Loading