Skip to content

Commit

Permalink
UPC_A support on iOS? #176
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jan 10, 2019
1 parent 241411a commit b2acb64
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ npm run demo-ng.ios (or demo.ios.device)
* ITF (also known as ITF14)
* PDF_417 (on Android only when passed in explicity via `formats`)
* QR_CODE
* UPC_A (on iOS only when passed in explicitly via `formats`, see [#176](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/176))
* UPC_A
* UPC_E

### Android only
Expand All @@ -58,6 +58,11 @@ npm run demo-ng.ios (or demo.ios.device)
### iOS only
* CODE_39_MOD_43

### A note about `UPC_A` and `EAN_13`
When either (or both) of these are specified, both can be returned.
You can check the actual type by inspecting the `format` property of the result object.
For details, see [#176](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/176).

## Installation
From the command prompt go to your app's root folder and execute:
```
Expand Down Expand Up @@ -169,6 +174,8 @@ Tip: during a scan you can use the volume up/down buttons to toggle the torch.
);
```

> Note that `result.format` above is one of [these](https://github.com/EddyVerbruggen/nativescript-barcodescanner/blob/241411a14f89171309bb94f3ca6da3bb45433e5e/src/barcodescanner-common.ts#L5).
#### JavaScript
```js
var BarcodeScanner = require("nativescript-barcodescanner").BarcodeScanner;
Expand Down
4 changes: 2 additions & 2 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<GridLayout>
<Barcode:BarcodeScannerView
class="scanner-round"
formats="QR_CODE, EAN_13"
formats="QR_CODE, EAN_13, CODE_128"
beepOnScan="true"
reportDuplicates="true"
preferFrontCamera="false"
Expand All @@ -30,7 +30,7 @@
</GridLayout>
</iOS>

<Label class="h3" text="Scan QR, EAN-13, or CODE_128"/>
<Label class="h3" text="Scan QR, UPC_A (including EAN_13), or CODE_128"/>
<Label class="body" text="You can use the volume buttons to toggle the torch." textWrap="true"/>

<Button class="btn btn-primary btn-rounded-sm" text="back camera, with flip" tap="{{ doScanWithBackCamera }}"/>
Expand Down
1 change: 0 additions & 1 deletion demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export class HelloWorldModel extends Observable {

private scan(front: boolean, flip: boolean, torch?: boolean, orientation?: string) {
this.barcodeScanner.scan({
formats: "QR_CODE, EAN_13, CODE_128",
cancelLabel: "EXIT. Also, try the volume buttons!", // iOS only, default 'Close'
cancelLabelBackgroundColor: "#333333", // iOS only, default '#000000' (black)
message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
Expand Down
5 changes: 3 additions & 2 deletions src/barcodescanner.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ export class BarcodeScanner {

const shouldReturnEAN13AsUPCA = (barcodeFormat: BarcodeFormat, value: string, requestedFormats?: string): boolean => {
return barcodeFormat === "EAN_13" &&
value.indexOf("0") === 0 &&
(!requestedFormats || requestedFormats.indexOf("UPC_A") > -1);
value.indexOf("0") === 0;
// why not add the line below? see https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/176
// && (!requestedFormats || requestedFormats.indexOf("UPC_A") > -1);
};

const getBarcodeFormat = (nativeFormat: string): BarcodeFormat => {
Expand Down

0 comments on commit b2acb64

Please sign in to comment.