mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix(barcode-scanner): check if iOS platform supports scanning (#3222)
This commit is contained in:
committed by
GitHub
parent
b60dd88702
commit
c27af9128d
@@ -0,0 +1,6 @@
|
||||
---
|
||||
barcode-scanner: patch
|
||||
barcode-scanner-js: patch
|
||||
---
|
||||
|
||||
On iOS, fixed an application crash happening when the scanner was started on the iOS Simulator (no camera available).
|
||||
@@ -269,20 +269,20 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
|
||||
scanFormats = [AVMetadataObject.ObjectType]()
|
||||
|
||||
(args.formats ?? []).forEach { format in
|
||||
if let formatValue = format.value {
|
||||
scanFormats.append(formatValue)
|
||||
} else {
|
||||
invoke.reject("Unsupported barcode format on this iOS version: \(format)")
|
||||
return
|
||||
}
|
||||
if let formatValue = format.value {
|
||||
scanFormats.append(formatValue)
|
||||
} else {
|
||||
invoke.reject("Unsupported barcode format on this iOS version: \(format)")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if scanFormats.isEmpty {
|
||||
for supportedFormat in SupportedFormat.allCases {
|
||||
if let formatValue = supportedFormat.value {
|
||||
scanFormats.append(formatValue)
|
||||
}
|
||||
for supportedFormat in SupportedFormat.allCases {
|
||||
if let formatValue = supportedFormat.value {
|
||||
scanFormats.append(formatValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.metaOutput!.metadataObjectTypes = self.scanFormats
|
||||
@@ -305,6 +305,13 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if camera is available on this platform (iOS simulator doesn't have cameras)
|
||||
let availableVideoDevices = discoverCaptureDevices()
|
||||
if availableVideoDevices.isEmpty {
|
||||
invoke.reject("No camera available on this device (e.g., iOS Simulator)")
|
||||
return
|
||||
}
|
||||
|
||||
var iOS14min: Bool = false
|
||||
if #available(iOS 14.0, *) { iOS14min = true }
|
||||
if !iOS14min && self.getPermissionState() != "granted" {
|
||||
|
||||
Reference in New Issue
Block a user