EddyVerbruggen / nativescript-barcodescanner

🔎 NativeScript QR / barcode (bulk)scanner plugin
MIT License
293 stars 73 forks source link

App Crash if formatString is Array (iOS) #255

Open two-bridges opened 3 years ago

two-bridges commented 3 years ago

If you pass an array to format attribute, the app running on a physical iOS device will crash.

eg. [formats]="['QR_CODE']"

Error: formatsString.split is not a function

It was my error to try to send an array, but it was very painful to solve this issue in a production app.

I guess it could throw an ugly error but best if it did not to crash the whole app.

Possible Solution:

add typeof formatsString before trying to use formatsString, as shown below:

/node_modules/nativescript-barcodescanner/barcodescanner.ios.js

const getBarcodeTypes = (formatsString) => {
    const types = [];
    if (typeof formatsString === "string" && formatsString) {
        let formats = formatsString.split(",");
        for (let format of formats) {
            format = format.trim();
            if (format === "QR_CODE")