2017-03-16 86 views
1

我想用Scandit sdk或插件掃描條形碼。如何在ionic2中的.ts文件中導入scandit插件。
我的代碼是如何在離子2中使用Scandit插件2

import { Component } from '@angular/core'; 

import { NavController } from 'ionic-angular'; 

import { BarcodeScanner } from 'ionic-native'; 

import { Platform } from 'ionic-angular' 

declare var Scandit; 
declare var picker; 

@Component({ 
selector: 'page-home', 
templateUrl: 'home.html' 
}) 
export class HomePage { 


constructor(public navCtrl: NavController) { 

} 
success(session) { 
alert(session.newlyRecognizedCodes[0].data);  
} 

failure(error) { 
alert("Failed: " + error);  
} 

scan() 
{ 
Scandit.License.setAppKey("My key"); 
var settings = new Scandit.ScanSettings(); 
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.EAN13, true); 
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.UPC12, true); 
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.EAN8, true);    
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.CODE39, true); 
settings.codeDuplicateFilter = -1; 
picker = new Scandit.BarcodePicker(settings); 
picker.continuousMode = true; 
picker.getOverlayView().setViewfinderDimension(0.9, 0.2, 0.6, 0.2); 
picker.setMargins(new Scandit.Margins(0, 0, 0, 200), null, 0); 
picker.show(success, null, failure); 
picker.startScanning(); 
} 
stop() 
{ 
picker.cancel(); 
} 

start() 
{ 
picker.startScanning(); 
picker.setMargins(new Scandit.Margins(0, 0, 0, 200), null, 0.5); 
picker.getOverlayView().setViewfinderDimension(0.9, 0.2, 0.6, 0.2); 
} 

} 

我寫的基於該鏈接的代碼 - http://krishjan.com/2016/10/27/multiple-barcode-scanning-in-ioniccordova-using-scandit-api/

但它不工作。我如何使用scandit插件掃描條形碼。

感謝您的回答。

回答

1

我解決我的問題,將插件導入的.ts文件中像這樣

import { Scanditsdk } from plugins/com.mirasense.scanditsdk.plugin/plugin.xml 

然後,它完美的作品。