Socket
Socket
Sign inDemoInstall

nativescript-barcodescanner

Package Overview
Dependencies
0
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nativescript-barcodescanner

Scan QR/barcodes with a {N} app.


Version published
Weekly downloads
74
decreased by-26%
Maintainers
1
Install size
1.21 MB
Created
Weekly downloads
 

Readme

Source

NativeScript BarcodeScanner

Scan a barcode (or a QR code, or a lot of other formats really)

Prerequisites

Set your Android target to level 23.

NativeScript 1.2.3+ for iOS, 1.3.0+ for Android (tns --version), so please upgrade if you need to.

If -for some reason- you need to build for {N} 1.2 on Android, please use this branch.

Installation

From the command prompt go to your app's root folder and execute:

tns plugin add nativescript-barcodescanner

Usage

function: scan

  var barcodescanner = require("nativescript-barcodescanner");

  barcodescanner.scan({
    cancelLabel: "Stop scanning", // iOS only, default 'Close'
    message: "Go scan something", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
    preferFrontCamera: false,     // Android only, default false
    showFlipCameraButton: true    // Android only, default false (on iOS it's always available)
  }).then(
      function(result) {
        console.log("Scan format: " + result.format);
        console.log("Scan text:   " + result.text);
      },
      function(error) {
        console.log("No scan: " + error);
      }
  )

function: available

Note that the Android implementation will always return true at the moment.

  var barcodescanner = require("nativescript-barcodescanner");

  barcodescanner.available().then(
      function(avail) {
        console.log("Available? " + avail);
      }
  );

function: hasCameraPermission / requestCameraPermission

On Android 6 you need to request permission to use the camera at runtime when targeting API level 23+. Even if the uses-permission tag for the Camera is present in AndroidManifest.xml.

Note that hasCameraPermission will return true when:

  • You're running this on iOS, or
  • You're targeting an API level lower than 23, or
  • You're using Android < 6, or
  • You've already granted permission.
  barcodescanner.hasCameraPermission().then(
      function(granted) {
        // if this is 'false' you probably want to call 'requestCameraPermission' now
        console.log("Has Camera Permission? " + result);
      }
  );

  // if no permission was granted previously this wil open a user consent screen
  barcodescanner.requestCameraPermission().then(
      function() {
        console.log("Camera permission requested");
      }
  );

Note that the scan function will also check fr permission and ask for it if it wasn't previously granted. If you're relying on that, then you should know that since we're not catching the consent result the user will then need to allow camera access and launch the scanner again.

Keywords

FAQs

Last updated on 27 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc