From f7d082352872218fd99c0cf2991145ec28395f04 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Thu, 4 Apr 2019 23:09:01 +0200 Subject: [PATCH] Added BRC_BW_FORMAT_UNSUPPORTED to not let PKBarcodeFormatCode128 to be used as backward barcode format --- src/messages.js | 1 + src/pass.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index 0b0739a..017260c 100644 --- a/src/messages.js +++ b/src/messages.js @@ -15,6 +15,7 @@ const debugMessages = { BRC_NOT_SUPPORTED: "Format not found among barcodes. Cannot set backward compatibility.", BRC_FORMATTYPE_UNMATCH: "Format must be a string or null. Cannot set backward compatibility.", BRC_AUTC_MISSING_DATA: "Unable to autogenerate barcodes. Data is not a string or an object with no message field", + BRC_BW_FORMAT_UNSUPPORTED: "This format is not supported (by Apple) for backward support. Please choose another one.", DATE_FORMAT_UNMATCH: "%s was not set due to incorrect date format.", LOAD_TYPES_UNMATCH: "Resource and name are not valid strings. No action will be taken for the specified medias.", LOAD_MIME: "Picture MIME-type: %s", diff --git a/src/pass.js b/src/pass.js index c157d0a..8ad39dc 100644 --- a/src/pass.js +++ b/src/pass.js @@ -411,7 +411,16 @@ class Pass { }, []); if (valid.length) { - this._props["barcode"] = valid[0]; + // With this check, we want to avoid that + // PKBarcodeFormatCode128 gets chosen automatically + // if it is the first. If true, we'll get 1 + // (so not the first index) + let barcodeFirstValidIndex = Number(valid[0].format === "PKBarcodeFormatCode128"); + + if (valid.length > 1) { + this._props["barcode"] = valid[barcodeFirstValidIndex]; + } + this._props["barcodes"] = valid; } @@ -469,6 +478,11 @@ class Pass { return this; } + if (format === "PKBarcodeFormatCode128") { + barcodeDebug(formatMessage("BRC_BW_FORMAT_UNSUPPORTED")); + return this; + } + // Checking which object among barcodes has the same format of the specified one. let index = this._props["barcodes"].findIndex(b => b.format.toLowerCase().includes(format.toLowerCase()));