Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you are creating your own Apache Cordova app and are installing the plugins, please use the following links corresponding to the version of Apache Cordova you are using:

  • v5.0.0+ - Note: you will need to install this version from the repository as the suggested add code will install the latest version.
  • v7.1.0+

...

What the code is doing is defining a success and failure function that will be passed along to the scan function of the scanner object. These functions will fire depending on whether your barcode reader is successful in scanning a given barcode or not. Inside of these functions, we define the behavior we wish to occur depending on the context. For both of these functions, a parameter will be passed that gives the relevant info needed; in a success function, the object that is passed contains a "text" property that contains the value of the barcode scanned scanner and a "format" property that contains the format type of the barcode scanned. In a failure function, the object passed is just a string containing the reason for the failure. You can see in the success function we are changing the value of the "code" textbox to be equal to the "text" property of the passed object called "result"; this changes the texboxtextbox's value to the scanned barcode's value. The if statement surrounding the scanner variable and scan call is checking to see if you are on mobile running Apache Cordova (which our client uses) first. If not it will automatically call the failure function (in this example nothing is passed into it, but you could pass it a string explaining that you are not on a mobile device), which simply throws an alert that displays the error.

...