ionic-team / ionic-team/capacitor-barcode-scanner
Discrepancy between documentation and implementation for scanBarcode method
- Dominant language
- TypeScript
- Stars
- 64
- Forks
- 47
- Avg merge
- 1h 55m
- Merged PRs (30d)
- 1
Description
According to the documentation found at [capacitorjs.com](https://capacitorjs.com/docs/apis/barcode-scanner#capacitorbarcodescanneroptions), the options for `scanBarcode` are as follows:
```typescript
{
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`
```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`
```swift
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.