ionic cordova plugin add cordova-plugin-cszbar
npm install --save @ionic-native/zbar
添加到NgModule
import { ZBar } from '@ionic-native/zbar';
@NgModule({
ders: [
ZBar
]
})
export class AppModule { }
使用
import { ZBar, ZBarOptions } from '@ionic-native/zbar';
constructor(private zbar: ZBar) { }
scan() {
let options: ZBarOptions = {
flash: 'off',
text_title: '掃碼',
drawSight: false
};
this.zbar.scan(options)
.then(result => {
alert("結(jié)果:" + result); // Scanned code
})
.catch(error => {
alert(error); // Error message
});
}