nativescript-barcodescanner
Advanced tools
Comparing version 0.0.8 to 1.0.0
@@ -1,3 +0,1 @@ | ||
var barcodescanner = {}; | ||
module.exports = barcodescanner; | ||
var barcodescanner = {}; |
@@ -7,2 +7,9 @@ var barcodescanner = require("./barcodescanner-common"); | ||
barcodescanner.available = function () { | ||
return new Promise(function (resolve) { | ||
// TODO a real implementation, like on iOS | ||
resolve(true); | ||
}); | ||
}; | ||
barcodescanner.scan = function(arg) { | ||
@@ -58,3 +65,2 @@ return new Promise(function (resolve, reject) { | ||
// TODO doesn't common do that already? | ||
module.exports = barcodescanner; |
var barcodescanner = require("./barcodescanner-common"); | ||
var frame = require("ui/frame"); | ||
barcodescanner.scan = function(arg) { | ||
return new Promise(function(resolve, reject) { | ||
// TODO implement | ||
resolve(true); | ||
barcodescanner.available = function () { | ||
return new Promise(function (resolve) { | ||
resolve(QRCodeReader.isAvailable()); | ||
}); | ||
}; | ||
// TODO doesn't common do that already? | ||
// TODO check camera PERMISSION beforehand: https://github.com/yannickl/QRCodeReaderViewController/issues/4 | ||
barcodescanner.scan = function (arg) { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
var closeButtonLabel = arg.cancelLabel || "Close"; | ||
var types = [AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, | ||
AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code, | ||
AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]; | ||
var bs = QRCodeReaderViewController.readerWithCancelButtonTitleMetadataObjectTypes(closeButtonLabel, types); | ||
bs.modalPresentationStyle = UIModalPresentationFormSheet; | ||
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference. | ||
var delegate = QRCodeReaderDelegateImpl.new().initWithCallback(function (reader, text, type) { | ||
// invoke the callback / promise | ||
if (text === undefined) { | ||
reject("Scan aborted"); | ||
} else { | ||
resolve({ | ||
format : type, | ||
text : text | ||
}); | ||
} | ||
// Remove the local variable for the delegate. | ||
delegate = undefined; | ||
}); | ||
bs.delegate = delegate; | ||
var topMostFrame = frame.topmost(); | ||
if (topMostFrame) { | ||
var vc = topMostFrame.currentPage && topMostFrame.currentPage.ios; | ||
if (vc) { | ||
vc.presentViewControllerAnimatedCompletion(bs, true, null); | ||
} | ||
} | ||
} catch (ex) { | ||
console.log("Error in barcodescanner.scan: " + ex); | ||
reject(ex); | ||
} | ||
}); | ||
}; | ||
var QRCodeReaderDelegateImpl = (function (_super) { | ||
__extends(QRCodeReaderDelegateImpl, _super); | ||
function QRCodeReaderDelegateImpl() { | ||
_super.apply(this, arguments); | ||
} | ||
QRCodeReaderDelegateImpl.new = function () { | ||
return _super.new.call(this); | ||
}; | ||
QRCodeReaderDelegateImpl.prototype.initWithCallback = function (callback) { | ||
this._callback = callback; | ||
return this; | ||
}; | ||
QRCodeReaderDelegateImpl.prototype.readerDidCancel = function (reader) { | ||
UIApplication.sharedApplication().keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, null); | ||
this._callback(reader); | ||
}; | ||
QRCodeReaderDelegateImpl.prototype.readerDidScanResultForType = function (reader, text, type) { | ||
UIApplication.sharedApplication().keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, null); | ||
this._callback(reader, text, type); | ||
}; | ||
QRCodeReaderDelegateImpl.ObjCProtocols = [QRCodeReaderDelegate]; | ||
return QRCodeReaderDelegateImpl; | ||
})(NSObject); | ||
module.exports = barcodescanner; |
{ | ||
"name": "nativescript-barcodescanner", | ||
"version": "0.0.8", | ||
"version": "1.0.0", | ||
"description" : "Scan QR/barcodes with a {N} app.", | ||
@@ -8,3 +8,4 @@ "main" : "barcodescanner.js", | ||
"platforms": { | ||
"android": "1.1.0" | ||
"android": "1.1.3", | ||
"ios": "1.2.0" | ||
} | ||
@@ -17,3 +18,14 @@ }, | ||
"keywords": [ | ||
"NativeScript" | ||
"NativeScript", | ||
"Barcode", | ||
"Barcode Scanner", | ||
"Aztec", | ||
"Code39", | ||
"Code93", | ||
"Code128", | ||
"EAN8", | ||
"EAN13", | ||
"PDF417", | ||
"QR", | ||
"UPCE" | ||
], | ||
@@ -20,0 +32,0 @@ "author": "Eddy Verbruggen <eddyverbruggen@gmail.com>", |
@@ -5,5 +5,7 @@ # NativeScript BarcodeScanner | ||
For Android, iOS support is planned! | ||
## Prerequisites | ||
Make sure you're using nativescript-cli 1.1.3 or up. | ||
Instructions for older versions have been dropped from this readme. | ||
## Prerequisites | ||
## Prerequisites for Android | ||
Check if you have Android-19 installed (required for building the ZXing library), run this from the command prompt: | ||
@@ -22,60 +24,19 @@ ``` | ||
## Instructions for nativescript-cli 1.1.3+ | ||
Installation with `tns --version` 1.1.3 and up is way easier, | ||
but at the moment of writing 1.1.3 is not yet released, but you can use [nativescript-cli master](https://github.com/nativescript/nativescript-cli) of course. | ||
So if you're impatient like me and don't want to install this plugin the hard way, upgrade your cli: | ||
## Installation | ||
From the command prompt go to your app's root folder and execute: | ||
``` | ||
git clone git@github.com:NativeScript/nativescript-cli.git | ||
cd nativescript-cli | ||
git submodule init | ||
git submodule update | ||
npm i | ||
grunt | ||
npm link | ||
``` | ||
Now, from the command prompt go to your app's root folder and execute: | ||
``` | ||
tns plugin add nativescript-barcodescanner | ||
``` | ||
That's it :) | ||
### iOS post-installation step | ||
Due to [this issue](https://github.com/NativeScript/ios-runtime/pull/266) in NativeScript frameworks installed | ||
from an iOS plugin are not correctly resolved. As a temporary fix you need to edit your `project.pbxproj` file | ||
and add the full path to the framework like `"\"/Users/eddyverbruggen/barcodescannertest/lib/iOS/BarcodeScannerFramework\"",` | ||
to both `FRAMEWORK_SEARCH_PATHS` sections (near the bottom of the file) or your project can't use the plugin | ||
and will crash if it does. | ||
## Instructions for nativescript-cli <= 1.1.2 | ||
So you're taking the harder path to barcodescanning heaven. Alright, follow these instructions closely! | ||
From the command prompt go to your app's `app` folder(!) and execute: | ||
``` | ||
tns plugin add nativescript-barcodescanner | ||
``` | ||
Still from the app folder, install the ZXing library for Android in your project: | ||
``` | ||
tns library add android ../node_modules/nativescript-barcodescanner/platforms/android/LibraryProject | ||
``` | ||
You will find this `activity` *outside* the `/manifest/application` section of `/platforms/android/AndroidManifest.xml`, move it *inside*: | ||
```xml | ||
<activity | ||
android:name="com.google.zxing.client.android.CaptureActivity" | ||
android:clearTaskOnLaunch="true" | ||
android:configChanges="orientation|keyboardHidden" | ||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" | ||
android:windowSoftInputMode="stateAlwaysHidden" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="com.google.zxing.client.android.SCAN"/> | ||
<category android:name="android.intent.category.DEFAULT"/> | ||
</intent-filter> | ||
</activity> | ||
``` | ||
## Usage | ||
### scan | ||
### function: scan | ||
```js | ||
@@ -85,14 +46,27 @@ var barcodescanner = require("nativescript-barcodescanner"); | ||
barcodescanner.scan({ | ||
message: "Go scan something", | ||
preferFrontCamera: false, | ||
showFlipCameraButton: true | ||
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); | ||
console.log("Scan format: " + result.format); | ||
console.log("Scan text: " + result.text); | ||
}, | ||
function(error) { | ||
console.log("~~~~~~~~~~~ Scan error: " + error); | ||
console.log("No scan: " + error); | ||
} | ||
) | ||
``` | ||
### function: available | ||
Note that the Android implementation will always return `true` at the moment. | ||
```js | ||
var barcodescanner = require("nativescript-barcodescanner"); | ||
barcodescanner.available().then( | ||
function(avail) { | ||
console.log("Available? " + avail); | ||
} | ||
); | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2359118
433
132
0
69