-
Notifications
You must be signed in to change notification settings - Fork 41
Description
According to the documentation found at capacitorjs.com, the options for scanBarcode are as follows:
{
hint: CapacitorBarcodeScannerTypeHint;
scanInstructions?: string;
scanButton?: boolean;
scanText?: string;
cameraDirection?: CapacitorBarcodeScannerCameraDirection;
scanOrientation?: CapacitorBarcodeScannerScanOrientation;
android?: {
scanningLibrary?: CapacitorBarcodeScannerAndroidScanningLibrary;
};
web?: {
showCameraSelection?: boolean; scannerFPS?: number;
};
}This suggests that hint is the only required parameter. This works as intended in Android.
However, trying the same in iOS (tested on iPadOS 18.7.1 specifically), this causes a Scanning parameters are invalid error. Analysing the code, I found that the error happens on this line
Pods/Development Pods/CapacitorBarcodeScanner/CapacitorBarcodeScannerPlugin.swift
guard let argumentsData = try? JSONSerialization.data(withJSONObject: call.jsObjectRepresentation),
let scanArguments = try? JSONDecoder().decode(OSBARCScanParameters.self, from: argumentsData) else {
call.sendError(with: OSBarcodeError.scanInputArgumentsIssue)
return
}Diving further into OSBARCScanParameters
OSBarcodeLib/OSBARCScanParameters
public struct OSBARCScanParameters {
/// Text to be displayed on the scanner view.
public let scanInstructions: String
/// Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
public let scanButtonText: String?
public let cameraDirection: OSBarcodeLib.OSBARCCameraModel
public let scanOrientation: OSBarcodeLib.OSBARCOrientationModel
public let hint: OSBarcodeLib.OSBARCScannerHint?
public init(scanInstructions: String, scanButtonText: String?, cameraDirection: OSBarcodeLib.OSBARCCameraModel, scanOrientation: OSBarcodeLib.OSBARCOrientationModel, hint: OSBarcodeLib.OSBARCScannerHint?)
}This suggests that scanInstructions, cameraDirection and scanOrientation are not optional. Adding these parameters to the scanBarcode call solves the issue as expected. On a related note, hint is not actually mandatory for iOS
===========
It may be helpful to update the documentation to clarify these platform-specific differences — specifically which parameters are required or optional on iOS versus Android.