Giter Site home page Giter Site logo

bitpay / cordova-plugin-qrscanner Goto Github PK

View Code? Open in Web Editor NEW
567.0 28.0 773.0 2.47 MB

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.

License: MIT License

JavaScript 41.13% Swift 14.86% HTML 3.26% Java 21.80% C# 17.75% CSS 1.20%
qrscanner device-camera video-preview camera cordova cordova-plugin qr qrcode qrcode-scanner qrcode-reader

cordova-plugin-qrscanner's Introduction

Build Status npm npm Dependency Status Commitizen friendly

cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps – available for the iOS, Android, Windows, and browser platforms.

QRScanner's native camera preview is rendered behind the Cordova app's webview, and QRScanner provides show and hide methods to toggle the transparency of the webview's background. This allows for a completely HTML/CSS/JS interface to be built inside the webview to control the scanner.

Examples

BitPay – Secure Bitcoin Wallet Copay Bitcoin Wallet Platform BitPocket Point Of Sale App
BitPay – Secure Bitcoin Wallet bitpay/copay BitPocket - Bitcoin Point of Sale App

Get Started

cordova plugin add cordova-plugin-qrscanner

Simply adding this plugin to the Cordova project will make the window.QRScanner global object available once the deviceready event propagates.

Usage

There are two primary steps to integrating cordova-plugin-qrscanner.

1. Get Permission Early (Optional)

This step is optional – if the best place for your app to ask for camera permissions is at the moment scanning begins, you can safely skip this step.

If there's a better place in your app's onboarding process to ask for permission to use the camera ("permission priming"), this plugin makes it possible to ask prior to scanning using the prepare method. The prepare method initializes all the infrastructure required for scanning to happen, including (if applicable) asking for camera permissions. This can also be done before attempting to show the video preview, making your app feel faster and more responsive.

// For the best user experience, make sure the user is ready to give your app
// camera access before you show the prompt. On iOS, you only get one chance.

QRScanner.prepare(onDone); // show the prompt

function onDone(err, status){
  if (err) {
   // here we can handle errors and clean up any loose ends.
   console.error(err);
  }
  if (status.authorized) {
    // W00t, you have camera access and the scanner is initialized.
    // QRscanner.show() should feel very fast.
  } else if (status.denied) {
   // The video preview will remain black, and scanning is disabled. We can
   // try to ask the user to change their mind, but we'll have to send them
   // to their device settings with `QRScanner.openSettings()`.
  } else {
    // we didn't get permission, but we didn't get permanently denied. (On
    // Android, a denial isn't permanent unless the user checks the "Don't
    // ask again" box.) We can ask again at the next relevant opportunity.
  }
}

2. Scan

Later in your application, simply call the scan method to enable scanning, and the show method to make the camera preview visible.

If you haven't previously prepared the scanner, the scan method will first internally prepare the scanner, then begin scanning. If you'd rather ask for camera permissions at the time scanning is attempted, this is the simplest option.

// Start a scan. Scanning will continue until something is detected or
// `QRScanner.cancelScan()` is called.
QRScanner.scan(displayContents);

function displayContents(err, text){
  if(err){
    // an error occurred, or the scan was canceled (error code `6`)
  } else {
    // The scan completed, display the contents of the QR code:
    alert(text);
  }
}

// Make the webview transparent so the video preview is visible behind it.
QRScanner.show();
// Be sure to make any opaque HTML elements transparent here to avoid
// covering the video.

Please see the full API docs for details about each method, error handling, and platform specific details.

Electron or NW.js usage without cordova-browser

If your app uses the Cordova Browser platform, simply adding the plugin to the Cordova project will make the window.QRScanner global object available once the deviceready event propagates. For apps not using cordova-browser, this plugin is also available as a simple javascript library.

The library uses the Universal Module Definition API, so it can simply be required by most build systems.

var QRScanner = require('QRScanner');

Or alternatively, the library can be included in a page as-is, and the QRScanner will be made available at window.QRScanner.

<script src="path/to/qrscanner/library.bundle.min.js"></script>

On the browser platform, performance is improved by running the processing-intensive scanning operation in a Web Worker. For more information about the browser platform, see Browser Platform Specific Details.

API

With the exception of QRScanner.scan(callback) and QRScanner.getStatus(callback), all callbacks are optional.

Prepare

var done = function(err, status){
  if(err){
    console.error(err._message);
  } else {
    console.log('QRScanner is initialized. Status:');
    console.log(status);
  }
};

QRScanner.prepare(done);

Request permission to access the camera (if not already granted), prepare the video preview, and configure everything needed by QRScanner. On platforms where possible, this also starts the video preview, saving valuable milliseconds and making it seem like the camera is starting instantly when QRScanner.show() is called. (These changes will only be visible to the user if QRScanner.show() has already made the webview transparent.)

Scan

var callback = function(err, contents){
  if(err){
    console.error(err._message);
  }
  alert('The QR Code contains: ' + contents);
};

QRScanner.scan(callback);

Sets QRScanner to "watch" for valid QR codes. Once a valid code is detected, it's contents are passed to the callback, and scanning is toggled off. If QRScanner.prepare() has not been called, this method performs that setup as well. On platforms other than iOS and Android, the video preview must be visible for scanning to function.

QRScanner.cancelScan(function(status){
  console.log(status);
});

Cancels the current scan. If QRScanner.prepare() has not been called, this method performs that setup as well. When a scan is canceled, the callback of the canceled scan() receives the SCAN_CANCELED error.

Show

QRScanner.show(function(status){
  console.log(status);
});

Configures the native webview to have a transparent background, then sets the background of the <body> and <html> DOM elements to transparent, allowing the webview to re-render with the transparent background.

To see the video preview, your application background must be transparent in the areas through which the preview should show.

The show and hide methods are the fastest way to toggle visibility of the scanner. When building the scanner into tab systems and similar layouts, this makes the application feel much more responsive. It's possible to reduce power consumption (to extend battery life on mobile platforms) by intellegently destroying the scanner when it's unlikely to be used for a long period of time. Before scanning is used again, you can re-prepare it, making the interface seem much more responsive when show is called.

Hide

QRScanner.hide(function(status){
  console.log(status);
});

Configures the native webview to be opaque with a white background, covering the video preview.

Lighting

QRScanner.enableLight(function(err, status){
  err && console.error(err);
  console.log(status);
});

Enable the device's light (for scanning in low-light environments). If QRScanner.prepare() has not been called, this method performs that setup as well.

QRScanner.disableLight(function(err, status){
  err && console.error(err);
  console.log(status);
});

Disable the device's light. If QRScanner.prepare() has not been called, this method performs that setup as well.

Camera Reversal

QRScanner defaults to the back camera, but can be reversed. If QRScanner.prepare() has not been called, these methods perform that setup as well.

QRScanner.useFrontCamera(function(err, status){
  err && console.error(err);
  console.log(status);
});

Switch video capture to the device's front camera.

QRScanner.useBackCamera(function(err, status){
  err && console.error(err);
  console.log(status);
});

Camera selection can also be done directly with the useCamera method.

var back = 0; // default camera on plugin initialization
var front = 1;
QRScanner.useCamera(front, function(err, status){
  err && console.error(err);
  console.log(status);
});

Switch video capture to the device's back camera.

Video Preview Control

QRScanner.pausePreview(function(status){
  console.log(status);
})

Pauses the video preview on the current frame (as if a snapshot was taken) and pauses scanning (if a scan is in progress).

QRScanner.resumePreview(function(status){
  console.log(status);
})

Resumes the video preview and continues to scan (if a scan was in progress before pausePreview()).

Open App Settings

QRScanner.getStatus(function(status){
  if(!status.authorized && status.canOpenSettings){
    if(confirm("Would you like to enable QR code scanning? You can allow camera access in your settings.")){
      QRScanner.openSettings();
    }
  }
});

Open the app-specific permission settings in the user's device settings. Here the user can enable/disable camera (and other) access for your app.

Note: iOS immediately kills all apps affected by permission changes in Settings. If the user changes a permission setting, your app will stop and only restart when they return.

Get QRScanner Status

QRScanner.getStatus(function(status){
  console.log(status);
});
{
  "authorized": Boolean
  "denied": Boolean
  "restricted": Boolean
  "prepared": Boolean
  "scanning": Boolean
  "previewing": Boolean
  "showing": Boolean
  "lightEnabled": Boolean
  "canOpenSettings": Boolean
  "canEnableLight": Boolean
  "currentCamera": Number
}

Retrieve the status of QRScanner and provide it to the callback function.

Status Object Properties

Name Description
authorized On iOS and Android 6.0+, camera access is granted at runtime by the user (by clicking "Allow" at the dialog). The authorized property is a boolean value which is true only when the user has allowed camera access to your app (AVAuthorizationStatus.Authorized). On platforms with permissions granted at install (Android pre-6.0, Windows Phone) this property is always true.
denied A boolean value which is true if the user permanently denied camera access to the app (AVAuthorizationStatus.Denied). Once denied, camera access can only be gained by requesting the user change their decision (consider offering a link to the setting via openSettings()).
restricted A boolean value which is true if the user is unable to grant permissions due to parental controls, organization security configuration profiles, or similar reasons.
prepared A boolean value which is true if QRScanner is prepared to capture video and render it to the view.
showing A boolean value which is true when the preview layer is visible (and on all platforms but browser, the native webview background is transparent).
scanning A boolean value which is true if QRScanner is actively scanning for a QR code.
previewing A boolean value which is true if QRScanner is displaying a live preview from the device's camera. Set to false when the preview is paused.
lightEnabled A boolean value which is true if the light is enabled.
canOpenSettings A boolean value which is true only if the users' operating system is able to QRScanner.openSettings().
canEnableLight A boolean value which is true only if the users' device can enable a light in the direction of the currentCamera.
canChangeCamera A boolean value which is true only if the current device "should" have a front camera. The camera may still not be capturable, which would emit error code 3, 4, or 5 when the switch is attempted. (On the browser platform, this value is false until the prepare method is called.)
currentCamera A number representing the index of the currentCamera. 0 is the back camera, 1 is the front.

Destroy

QRScanner.destroy(function(status){
  console.log(status);
});

Runs hide, cancelScan, stops video capture, removes the video preview, and deallocates as much as possible. Basically reverts the plugin to it's startup-state.

Error Handling

Many QRScanner functions accept a callback with an error parameter. When QRScanner experiences errors, this parameter contains a QRScannerError object with properties name (String), code (Number), and _message (String). When handling errors, rely only on the name or code parameter, as the specific content of _message is not considered part of the plugin's stable API. Particularly if your app is localized, it's also a good idea to provide your own message when informing the user of errors.

QRScanner.scan(function(err, contents){
  if(err){
    if(err.name === 'SCAN_CANCELED') {
      console.error('The scan was canceled before a QR code was found.');
    } else {
      console.error(err._message);
    }
  }
  console.log('Scan returned: ' + contents);
});

Possible Error Types

Code Name Description
0 UNEXPECTED_ERROR An unexpected error. Returned only by bugs in QRScanner.
1 CAMERA_ACCESS_DENIED The user denied camera access.
2 CAMERA_ACCESS_RESTRICTED Camera access is restricted (due to parental controls, organization security configuration profiles, or similar reasons).
3 BACK_CAMERA_UNAVAILABLE The back camera is unavailable.
4 FRONT_CAMERA_UNAVAILABLE The front camera is unavailable.
5 CAMERA_UNAVAILABLE The camera is unavailable because it doesn't exist or is otherwise unable to be configured. (Also returned if QRScanner cannot return one of the more specific BACK_CAMERA_UNAVAILABLE or FRONT_CAMERA_UNAVAILABLE errors.)
6 SCAN_CANCELED Scan was canceled by the cancelScan() method. (Returned exclusively to the QRScanner.scan() method.)
7 LIGHT_UNAVAILABLE The device light is unavailable because it doesn't exist or is otherwise unable to be configured.
8 OPEN_SETTINGS_UNAVAILABLE The device is unable to open settings.

Platform Specific Details

This plugin attempts to properly abstract all the necessary functions of a well-designed, native QR code scanner. Here are some platform specific details it may be helpful to know.

iOS

This plugin is always tested with the latest version of Xcode. Please be sure you have updated Xcode before installing.

If you run into issues in your own project, try the test project in this repo to confirm your environment is set up properly: npm run gen-tests && npm run test:ios.

Android

On Android, calling pausePreview() will also disable the light. However, if disableLight() is not called, the light will be reenabled when resumePreview() is called.

If you run into issues in your own project, try the test project in this repo to confirm your environment is set up properly: npm run gen-tests && npm run test:android.

Permissions

Unlike iOS, on Android >=6.0, permissions can be requested multiple times. If the user denies camera access, status.denied will remain false unless the user permanently denies by checking the Never ask again checkbox. Once status.denied is true, openSettings() is the only remaining option to grant camera permissions.

Because of API limitations, status.restricted will always be false on the Android platform. See #15 for details. Pull requests welcome!

Windows

Before testing - ensure the Windows Phone SDK is installed. In order to deploy from the command line Windows Phone 8.0 SDK and Visual Studio 2012 update 2 (or later) must be installed. Visual Studio 2015 is recommended for debugging Windows desktop apps.

The Windows platform renders an impervious white layer behind its browser- the video preview is not behind the webView, but is actually an HTML element that is carefully managed. Hide and show change the style properties (visibility) of the preview.

Browser

While the browser implementation matches the native mobile implementations very closely, the platform itself does not. Notably:

  • multiple cameras – most laptops/desktops do not have access to multiple cameras – so there is no concept of a "front" or "back" camera
  • light – we are not aware of any devices for the browser platform which have a "light" (aka. "torch") – should a device like this be produced, and if this spec is implemented by Chromium, this plugin will attempt to support it.

The browser implementation of this plugin is designed to abstract these platform differences very thoroughly. It's recommended that you focus your development efforts on implementing this plugin well for one of the mobile platform, and the browser platform implementation will degrade gracefully from there.

Video Preview DOM Element

Unlike the other platforms, it's not possible to spawn the <video> preview behind the <html> and <body> using only Javascript. Trying to mimick the effect by making the element a sibling to either the <html> or <body> elements also produces inconsistent results (ie: no rendering on Chromium). Instead, this plugin appends the <video> element as the final child of the <body> element, and applies styling to cover the entire background.

As a consequence, you should assume that your <body> element will be completely obscured from view as soon as the plugin is prepare()ed. When building your application, apply styling you might otherwise apply to the <body> element to a child "container" <div> or other element. To show the video preview, call the show() method and make this container transparent.

Privacy Lights

Most devices now include a hardware-level "privacy light", which is enabled when the camera is being used. To prevent this light from being "always on" when the app is running, the browser platform disables/enables use of the camera with the hide, show, pausePreview, and resumePreview methods. If your implementation works well on a mobile platform, you'll find that this addition provides a great head start for a solid browser implementation.

For this same reason, scanning requires the video preview to be active, and the pausePreview method will also pause scanning on the browser platform. (Calling resumePreview will continue the scan.)

Camera Selection

When the prepare method runs, the browser platform attempts to select the best camera as the "back" camera (the default camera). If a "next-best" camera is available, that camera will be selected as the "front" camera. Camera switching is intended to be "togglable", so this plugin has no plans to support access to more than 2 cameras.

The "back" camera is selected by the following criteria:

  1. facingMode – if a camera with a facingMode of environment exists, we use this one.
  2. resolution – If multiple environment cameras are available, the highest resolution camera is selected. If no back-facing cameras exist, we default to the highest resolution camera available.

If more cameras are available, the "front" camera is then chosen from the highest resolution camera remaining.

Light

The browser platform always returns the boolean status.canEnableLight as false, and the enableLight/disableLight methods throw the LIGHT_UNAVAILABLE error code.

status.canEnableLight is camera specific, meaning it will return false if the camera in use does not have a flash.

Using Status.authorized

Both Electron and NW.js automatically provide authorization to access the camera (without user confirmation) to bundled applications. This difference can't be detected via an API this plugin can implement, so the authorized property on any returned Status objects will be false on startup, even when it should be true. You should adjust your code to assume that these platforms are always authorized. (ie: Skip "permission priming" on these platforms.)

On the browser platform, the authorized field is set to true if at least one camera is available and the user has granted the application access to at least one camera. On Electron and NW.js, this field can reliably be used to determine if a camera is available to the device.

Adjusting Scan Speed vs. CPU/Power Usage (uncommon)

On the browser platform, it's possible to adjust the interval at which QR decode attempts occur – even while a scan is happening. This enables applications to intellegently adjust scanning speed in different application states. QRScanner will check for the presence of the global variable window.QRScanner_SCAN_INTERVAL before scheduling each next QR decode. If not set, the default of 130 (milliseconds) is used.

Typescript

Type definitions for cordova-plugin-qrscanner are available in the DefinitelyTyped project.

Contributing & Testing

To contribute, first install the dependencies:

npm install

Then setup the test project:

npm run gen-tests

This will create a new cordova project in the cordova-plugin-test-projects directory next to this repo, install cordova-plugin-qrscanner, and configure the Cordova Plugin Test Framework. Once the platform tests are generated, the following commands are available:

  • npm run test:android
  • npm run test:browser
  • npm run test:ios
  • npm run test:windows

Both Automatic Tests (via Cordova Plugin Test Framework's built-in Jasmine) and Manual Tests are available. Automatic tests confirm the existence and expected structure of the javascript API, and manual tests should be used to confirm functionality on each platform.

The manual tests for the library are available without the cordova test project:

  • npm run test:library

The build for this repo currently only confirms javascript style and syntax with jshint. Pull requests with additional automated test methods are welcome!

cordova-plugin-qrscanner's People

Contributors

abcd-ca avatar bitjson avatar cgodley avatar cmgustavo avatar elledienne avatar greenkeeperio-bot avatar majochoc avatar matiu avatar nacardin avatar stefanhuber avatar vially avatar zimzimple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-qrscanner's Issues

White background in front of view

I can't get this app to work. There seems to be always a white screen in front of the camera view.

Even when I cloned the test repository (qrscanner-test) there was a white screen in front. You could tell the plugin was working because it would scan, and when you swiped down you could see the top of the camera view because you basically swiped the whole app down.
When calling the Hide function, there was only white when you swiped down, but after calling show again, you could see parts of the view on top or bottom when swiping.

I'm pretty sure I'm not forgetting an html layer because it shows the same behaviour in the test repository, and according to the status thingie everything seems to be working fine too.
I'm using iOS 10.0.1 and the latest version of Phonegap (6.3.3) and XCode (8.0).

I hope you have a clue of what's going on because I don't 😞

{"authorized":true,"denied":false,"restricted":false,"prepared":true,"scanning":true,"previewing":true,"showing":true,"lightEnabled":false,"canOpenSettings":true,"canEnableLight":true,"canChangeCamera":true,"currentCamera":0}

Unable to make release build on iOS

First off, great plugin, guys! It's crazy fast and on android it runs amazingly.

I have some issues on iOS though. I have a ionic framework project and when I build the project normally everything is OK. When I build it for release I have the output below.

I am running Cordova v 6.4.0 and xcode 8.0.

Thanks for the help and happy new year!

ld: warning: ignoring file /app/fitpass-user-app/platforms/ios/build/emulator/libCordova.a, file was built for archive which is not the architecture being linked (i386): /app/fitpass-user-app/platforms/ios/build/emulator/libCordova.a
Undefined symbols for architecture i386:
  "_CDVPageDidLoadNotification", referenced from:
      Fitpass_Romania.QRScanner.pluginInitialize () -> () in QRScanner.o
  "_CDVPluginHandleOpenURLNotification", referenced from:
      -[CDVInAppBrowser openInSystem:] in CDVInAppBrowser.o
  "_OBJC_CLASS_$_CDVAppDelegate", referenced from:
      _OBJC_CLASS_$_AppDelegate in AppDelegate.o
  "_OBJC_CLASS_$_CDVCommandDelegateImpl", referenced from:
      _OBJC_CLASS_$_MainCommandDelegate in MainViewController.o
  "_OBJC_CLASS_$_CDVCommandQueue", referenced from:
      _OBJC_CLASS_$_MainCommandQueue in MainViewController.o
  "_OBJC_CLASS_$_CDVInvokedUrlCommand", referenced from:
      objc-class-ref in QRScanner.o
  "_OBJC_CLASS_$_CDVPlugin", referenced from:
      _OBJC_CLASS_$_FacebookConnectPlugin in FacebookConnectPlugin.o
      _OBJC_CLASS_$_CDVInAppBrowser in CDVInAppBrowser.o
      _OBJC_CLASS_$_IntercomBridge in IntercomBridge.o
      _OBJC_CLASS_$_SQLitePlugin in SQLitePlugin.o
      _OBJC_CLASS_$_Diagnostic in Diagnostic.o
      _OBJC_CLASS_$_QRScanner in QRScanner.o
  "_OBJC_CLASS_$_CDVPluginResult", referenced from:
      objc-class-ref in FacebookConnectPlugin.o
      objc-class-ref in CDVInAppBrowser.o
      objc-class-ref in IntercomBridge.o
      objc-class-ref in SQLitePlugin.o
      objc-class-ref in Diagnostic.o
      objc-class-ref in QRScanner.o
  "_OBJC_CLASS_$_CDVUIWebViewDelegate", referenced from:
      objc-class-ref in CDVInAppBrowser.o
  "_OBJC_CLASS_$_CDVUserAgentUtil", referenced from:
      objc-class-ref in CDVInAppBrowser.o
  "_OBJC_CLASS_$_CDVViewController", referenced from:
      _OBJC_CLASS_$_MainViewController in MainViewController.o
  "_OBJC_METACLASS_$_CDVAppDelegate", referenced from:
      _OBJC_METACLASS_$_AppDelegate in AppDelegate.o
  "_OBJC_METACLASS_$_CDVCommandDelegateImpl", referenced from:
      _OBJC_METACLASS_$_MainCommandDelegate in MainViewController.o
  "_OBJC_METACLASS_$_CDVCommandQueue", referenced from:
      _OBJC_METACLASS_$_MainCommandQueue in MainViewController.o
  "_OBJC_METACLASS_$_CDVPlugin", referenced from:
      _OBJC_METACLASS_$_FacebookConnectPlugin in FacebookConnectPlugin.o
      _OBJC_METACLASS_$_CDVInAppBrowser in CDVInAppBrowser.o
      _OBJC_METACLASS_$_IntercomBridge in IntercomBridge.o
      _OBJC_METACLASS_$_SQLitePlugin in SQLitePlugin.o
      _OBJC_METACLASS_$_Diagnostic in Diagnostic.o
      _OBJC_METACLASS_$_QRScanner in QRScanner.o
  "_OBJC_METACLASS_$_CDVViewController", referenced from:
      _OBJC_METACLASS_$_MainViewController in MainViewController.o
  "_UTTypeConformsTo", referenced from:
      -[PodIntercom_FLAnimatedImage initWithAnimatedGIFData:optimalFrameCacheSize:predrawingEnabled:] in Intercom(FLAnimatedImage.o)
  "_UTTypeCopyPreferredTagWithClass", referenced from:
      -[PodIntercom_AFStreamingMultipartFormData appendPartWithFileURL:name:error:] in Intercom(AFURLRequestSerialization.o)
      ___60+[PodIntercom_ITBUpload createUploadForAssetUrl:completion:]_block_invoke in Intercom(ITBUpload.o)
  "_UTTypeCreatePreferredIdentifierForTag", referenced from:
      -[PodIntercom_AFStreamingMultipartFormData appendPartWithFileURL:name:error:] in Intercom(AFURLRequestSerialization.o)
  "_kUTTagClassFilenameExtension", referenced from:
      -[PodIntercom_AFStreamingMultipartFormData appendPartWithFileURL:name:error:] in Intercom(AFURLRequestSerialization.o)
  "_kUTTagClassMIMEType", referenced from:
      -[PodIntercom_AFStreamingMultipartFormData appendPartWithFileURL:name:error:] in Intercom(AFURLRequestSerialization.o)
      ___60+[PodIntercom_ITBUpload createUploadForAssetUrl:completion:]_block_invoke in Intercom(ITBUpload.o)
      -[PodIntercom_AFStreamingMultipartFormData appendPartWithFileURL:name:error:] in Intercom(AFURLRequestSerialization.o)
      ___60+[PodIntercom_ITBUpload createUploadForAssetUrl:completion:]_block_invoke in Intercom(ITBUpload.o)
  "_kUTTypeGIF", referenced from:
      -[PodIntercom_FLAnimatedImage initWithAnimatedGIFData:optimalFrameCacheSize:predrawingEnabled:] in Intercom(FLAnimatedImage.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
    Ld /Users/macbookpro/Library/Developer/Xcode/DerivedData/Fitpass_Romania-awasfszkgkeiqlbnvhsazwixihie/Build/Intermediates/Fitpass\ Romania.build/Release-iphonesimulator/Fitpass\ Romania.build/Objects-normal/i386/Fitpass\ Romania normal i386
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/app/fitpass-user-app/platforms/ios/cordova/build-release.xcconfig,-workspace,Fitpass Romania.xcworkspace,-scheme,Fitpass Romania,-configuration,Release,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 5s,build,CONFIGURATION_BUILD_DIR=/app/fitpass-user-app/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/app/fitpass-user-app/platforms/ios/build/sharedpch

Objective C code

Hi,
I am having issue with integration of swift file in objective c project.
Please help me with objective c .h and .m files.

destroy on ios crashes

Hi,

When I use QRscanner on Cordova IOS it crashes on the line 330 (self.captureVideoPreviewLayer!.removeFromSuperlater()

when I call destroy.

Crosswalk support

I create a new project to test this plugin,and it work fine.But when i add crosswalk in my project,it shown a blank screen,and go back previous page,the screen flashed.

Can I use without cordova?

I am developing a web app and I hope to implement a qr scanner. I came across this library and it looks very robust. I installed it via npm and tried to require('cordova-plugin-qrscanner') as I have done with my other npm modules. I am kind of confused as to how this library can be integrated into my App or if its even possible. I am not using any front end frameworks. Am I completely missing something here? Any clarification would be great. Thanks!

Deprecated URL.createObjectURL(stream) is used

Chrome 57 beta logs the following warning when scan() is called:

URL.createObjectURL(stream) is deprecated! Use elem.srcObject = stream instead!

Mozilla Devoloper Network:

The use of a MediaStream object as an input to this method is in the process of being deprecated. Discussions are ongoing about whether or not it should be removed outright. As such, you should try to avoid using this method with MediaStreams, and should use HTMLMediaElement.srcObject() instead.

Not compatible with WKWebView

I've looked at all elements in my webview tree, and can't find any elements in the path that don't have a transparent background.

Status shows that the webview background is transparent. I can scan and get results, but can't see the preview. Just a white screen (well grayish? I can see a difference in the screen and status bar).
device is iPhone 5, iOS 9.3.1, xCode 7.3. App is Meteor 1.3 with Cordova.
Any ideas of what else to look for?

Here's the status object from the console:

authorized: true
canEnableLight: true
canOpenSettings: true
currentCamera: 0
denied: false
lightEnabled: false
prepared: true
previewing: true
restricted: false
scanning: true
webviewBackgroundIsTransparent: true

Not working cordova-plugin-qrscanner

Hello,

I have onesignal-cordova-plugin plugin installed on my cordova android app, when install your plugin after then run cordova project that time getting gradlew error.. if remove the onesignal-cordova-plugin then proper working. I like your package but not working for android

I think conflict file of plugin.

Please give me a suggestion.

gradle error

Android: no way of confirming `status.restricted`

On iOS, the restricted field is set when parental controls or organization security profiles disable camera usage. In these cases, users are actually unable to allow the camera permission. The status.restricted field is set to true to allow app developers to better tailor the experience to these users (by not trying to openSettings() and instead asking them to contact a company admin, for example).

Android documentation is currently silent on how to detect if a Device Management Policy has disabled use of the camera: https://support.google.com/edu/android/answer/3429624 (Device settings > Allow camera)

(Half) white screen

Sometimes i get a white or a half white screen on the First load on my iphone. Going to an other page and back solves it.

Imgur

status is null

// Make sure the user will give your app camera access when prompted, then:
QRScanner.prepare(onDone); // prompt for access

function onDone(status){

status is null !!!!!!!!!!!?
and there is nothing when calling qrscan

if (!status.authorized) {
// the video preview will remain black, and scanning is disabled
// you can try asking the user again, but you'll have to use QRScanner.openSettings().
}
}

// later in your app:

QRScanner.show(); // optional: make the webview transparent so the video preview is visible behind it

QRScanner.scan(displayContents); // scan until something is found

function displayContents(text){
alert(text);
}

Automate version changes

We need to be sure to increment the version in config.xml as well as package.json, since cordova seems to add that version as the spec when the plugin is added via:

cordova plugin add cordova-plugin-qrscanner --save

Right now, the above results in the following being added to config.xml, even though the currently deployed version on npm is 2.3.4:

<plugin name="cordova-plugin-qrscanner" spec="~2.2.0" />

It would be good to add something to the prep-release npm script to copy the package.json version over to config.xml.

Android: Scanning area limited to center of camera preview (portrait mode)

The scanner only detects the QR Code if it's in the middle of the camera preview. For example, if you position the camera so that the QRCode is in the upper right corner of the BarcodeView preview, the QR Code will not be detected. Once you move the camera so the QR Code is in the middle, it detects it instantly. Need to change the scanning area to take up as much of the camera preview as possible so the QR Code can be scanned from anywhere, not just the middle.

Edit:
I just discovered that it scans the entire video preview when the camera is in landscape mode. This issue only occurs when the camera is in portrait mode.

Android. Nothing appears on screen.

Installed on a ionic tab's project, and debuggued in a controller, after device ready.
Running in a tablet Samsung Tab 2. 10.1.
Plugin is recognized, authorized, and run without errors, but nothing appears on screen.

angular.module('starter.controllers', [])

.controller('DashCtrl', function($ionicPlatform, $scope) { 
$ionicPlatform.ready(function() {

    alert(window.QRScanner);

    try {

        window.QRScanner.prepare(

            function onDone(err, status) {
                if (err) {
                    alert(err);
                }
                if (status.authorized) {

                    alert("authorized");

                    window.QRScanner.show(

                        function(status) {

                            window.QRScanner.scan(

                                function(err, text) {

                                    alert("QRScanner.scan");

                                    if (err) {
                                        alert(err);
                                    } else {
                                        alert(text);
                                    }
                                }
                            );
                        }
                    );
                } else if (status.denied) {
                    alert("denied");
                } else {
                    alert("else");
                }
            }
        );
    } catch (err) {
        alert(err);
    };
});

})

iOS: pausePreview() should pause scanning

If currently scanning when calling pausePreview(), scanning should be paused along with the video preview and resumed on call to resumePreview(). Browser and Android platform already do this.
14cb145

Ability to zoom

I have experimented with the plugin and everything seems to work great. Our QR codes are rather small and it would be a great help if we somehow could control the camera zoom. If we get to close to the QR code then it becomes blurry. For our purposes a setting of e.g. 1.5 zoom on .scan would be great.

Why I am not getting scan screen?

Hi,

Using below code, why nothing is happening when I run this function?

<div data-options="dxView : { name: 'scan', title: 'scan', disableCache: true } " >
    <div data-options="dxContent : { targetPlaceholder: 'content' } " class="dx-content-background">
        <br /><br />
        <div style="width: 100px; height: 100px;"></div>
        <button id="btnScan"> Scan Now </button>
    </div>
</div>
function scan_now()
{
    // For the best user experience, make sure the user is ready to give your app 
    // camera access before you show the prompt. On iOS, you only get one chance. 
 
    QRScanner.prepare(onDone); // show the prompt 
 
    function onDone(err, status){
        if (err)
        {
            // here we can handle errors and clean up any loose ends. 
            alert(err);
        }
        if (status.authorized)
        {
            // alert("authorized");
            // W00t, you have camera access and the scanner is initialized. 
            // QRscanner.show() should feel very fast.
            QRScanner.show();

            QRScanner.scan(displayContents);

            function displayContents(err, text)
            {
                if (err) {
                    alert("error scan");
                    // an error occurred, or the scan was canceled (error code `6`) 
                } else {
                    alert(text);
                    // The scan completed, display the contents of the QR code: 
                }
            }

            alert("scanned");
        }
        else if (status.denied)
        {
            alert("denid");
            // The video preview will remain black, and scanning is disabled. We can 
            // try to ask the user to change their mind, but we'll have to send them 
            // to their device settings with `QRScanner.openSettings()`. 
        }
        else
        {
            alert("else other");
            // we didn't get permission, but we didn't get permanently denied. (On 
            // Android, a denial isn't permanent unless the user checks the "Don't 
            // ask again" box.) We can ask again at the next relevant opportunity. 
        }
    }
}

Thanks,
Jassim

Can't install directly from GitHub

failed to install the plug in due to the following error.

ENOENT, no such file or directory 'C:\Cordova\TestingProject\plugins\cordova-plugin-qrscanner\www\www.min.js'

Installation / testing issues

I had some issues with the installation for testing the plugin - just in case i'm not the only one.

  1. gulp dependency is not noted anywhere (i use grunt), so i had to install.
    Of course you can see from gulpfile.js and reading the output, but it may be helpful to note that.

  2. webpack dependency seems to be tricky, i had to downgrade to exactly "2.1.0-beta.22".
    Not sure why exactly it did not work for me, but i'm not the only one: roots/sage#1720

Thank for maintaining this awesome plugin.

Remove Husky

When the plugin is installed on the Copay project, I'm getting this error when trying to commit on Windows OS:

 git commit -m "example"

> husky - npm run -s commitmsg

C:\Users\Gabriel\Documents\copay\plugins\cordova-plugin-qrscanner\node_modules\validate-commit-msg\lib\getGitFolder.js:8
    throw new Error('Cannot find file ' + gitDirLocation);
    ^

Error: Cannot find file ./.git
    at getGitFolder (C:\Users\Gabriel\Documents\copay\plugins\cordova-plugin-qrscanner\node_modules\validate-commit-msg\lib\getGitFolder.js:8:11)
    at Object.<anonymous> (C:\Users\Gabriel\Documents\copay\plugins\cordova-plugin-qrscanner\node_modules\validate-commit-msg\lib\cli.js:22:42)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

> husky - commit-msg hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit' 

Other types of barcodes?

Are there plans to broaden the scanning capabilities with, for example UPC, EAN, CODE and other codes?

Add screenshots to readme

We should add some screenshots of the QR scanner in use with various UIs. Might help to get the message across that the UI is implemented in browserland.

Swift3 + viewfinder implementation

I forked the project and I converted it to Swift3 (it was quite easy to be honest), I also added a feature that adds a viewfinder during the scanning (a very simple square around the detected code).

Would you be interested in a PR?

Using with Ionic: making the background transparent in Ionic 1

So i managed to get the plugin working all fine and reading the QR's really good but my proble comes with the preview, im not able to make all the ionic bullshit to be transparent, i need help.

<ion-view hide-nav-bar="true">
    <ion-content class="transparent" has-header="false" overflow-scroll="false">
      <button class="animated bounceInUp button button-assertive" ng-click="scanQR()" >
          Start Scan
      </button>
    </ion-content>
</ion-view>

thats the .html binded to the controller where i call QRScanner.show();

The thing is that the ionic ion-view has a inherit class called "pane" that puts a background, i dont know how to remove that class in this specific page and if i do so in the chrome developer window, i can see the camera preview but the sidemenu is on top of that due to all my elemnts extending from the side-menu.

How can i remove the inherit background of the ionic ion-view without screwing all the app?

I will really apreciate any help, sorry for my english.

Regards

Windows Testing issue

When testing windows, Windows platform is not added automatically.
You have to run cordova platform add windows before npm run test:windows

Error when using PhoneGap Build Cloud

I have been working all morning on getting this working, and need some help if anyone can lend a hand!

When you put the plugin into the config.xml and attempt to build it on PhoneGap Build it throws an error about the SWIFT needing a legacy version. Currently I am building with swift 3.0, what does this need? Or do I need to add a preference to make the plugin work?

  • keoir

I used ionic2 installed this plugin can't display camera preview

My develop environment

Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v4.4.5
Xcode version: Xcode 7.3.1 Build version 7D1014

Building the tests

I have a couple of issues -

  1. The plugins are not being downloaded from the registry and I am using the git path - not sure how to resolve this
  2. The AndroidManifest.xml has a package attribute with a value that contains {{TIMESTAMP}} - this is not being parsed - get an error at "{". Can I create the package name without this - where should I change this ?

How to make this plugin work with Ionic/angularjs?

I’m using Ionic/angular for my cordova app and the default barcodescanner plugin is shit. (Waaayyyyyyyyyy too slow). Looking to integrate this scanner but can’t find the right way to do it.

Can anyone gimme a clue please ?

Thanks!

ionic2 IOS 10 not able to preview

HI
I have spent 4-5 hours to make this plugin working in ionic2 on ios 10
But only visible when I remove the ion-nav component

Why you guys wasting community time if this plugin does not support ios just put in readme.md

Also I want ti mention that the scanning process is working only the preview is not visible

Please reply asap.
Waiting for response

Library: error is thrown when optional callbacks are not included

The following methods do not require callbacks, and should not throw errors if a callback isn't provided:

QRScanner.prepare();
QRScanner.show();
QRScanner.pausePreview();
QRScanner.resumePreview();
QRScanner.useFrontCamera();
QRScanner.useBackCamera();
QRScanner.enableLight();
QRScanner.disableLight();
QRScanner.cancelScan();
QRScanner.destroy();

How to cancel scanning on ios

Hello,

I have a cordova project running well on iOS and Android. When someone wants to cancel the scanning, in Android I can do capturing the backbutton, but iOS have not such button/event, so, how can I make the user be able to cancel the scanning?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.