ionic扫码

2019-01-15  本文已影响0人  一脚门万

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("结果:" + result); // Scanned code
      })
      .catch(error => {
        alert(error); // Error message
      });
  }
上一篇 下一篇

猜你喜欢

热点阅读