awesome-cordova-plugins/src/plugins/barcodescanner.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-02-02 22:35:45 +08:00
import {Plugin, Cordova} from './plugin';
/**
* @name BarcodeScanner
* @description
2016-02-02 22:35:45 +08:00
* The Barcode Scanner Plugin opens a camera view and automatically scans a barcode, returning the data back to you.
*
2016-02-08 06:12:13 +08:00
* Requires Cordova plugin: `phonegap-plugin-barcodescanner`. For more info, please see the [BarcodeScanner plugin docs](https://github.com/phonegap/phonegap-plugin-barcodescanner).
2016-02-02 22:35:45 +08:00
*
* @usage
* ```js
2016-02-08 06:12:13 +08:00
* BarcodeScanner.scan().then((barcodeData) => {
2016-02-02 22:35:45 +08:00
* // Success! Barcode data is here
* }, (err) => {
* // An error occurred
* });
* ```
*/
@Plugin({
plugin: 'phonegap-plugin-barcodescanner',
pluginRef: 'cordova.plugins.barcodeScanner',
repo: 'https://github.com/phonegap/phonegap-plugin-barcodescanner'
2016-02-02 22:35:45 +08:00
})
export class BarcodeScanner {
2016-02-08 06:12:13 +08:00
/**
* Open the barcode scanner.
* @return Returns a Promise that resolves with scanner data, or rejects with an error.
2016-02-08 06:12:13 +08:00
*/
2016-02-02 22:35:45 +08:00
@Cordova()
2016-02-08 06:12:13 +08:00
static scan(){
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
};
// Not well supported
// @Cordova()
// static encode(type, data){};
2016-02-02 22:35:45 +08:00
}