ionic扫码

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
      });
  }

你可能感兴趣的:(ionic扫码)