Flutter教程

Ionic实战视频教程(跨平台): https://www.itying.com/goods-1067.html

Flutter实战视频教程(跨平台): https://www.itying.com/goods-1176.html

QR Scanner

Contents

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps.

Requires Cordova plugin: cordova-plugin-qrscanner. For more info, please see the QR Scanner plugin docs.

https://github.com/bitpay/cordova-plugin-qrscanner

联系我们?

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic's experts offer official maintenance, support, and integration help.

Contact Us Today!

Ionic 扫码 QR Scanner插件的安装(Installation)

ionic cordova plugin add cordova-plugin-qrscanner npm install @ionic-native/qr-scanner
Ionic EE comes with fully supported and maintained plugins from the Ionic Team. Learn More or Contact Us
ionic enterprise register --key=YOURPRODUCTKEY npm install @ionic-enterprise/qr-scanner

Ionic 扫码 QR Scanner插件支持的平台(Supported Platforms)

  • Android
  • Browser
  • iOS
  • Windows

Ionic 扫码 QR Scanner插件的用法(Usage)

import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner/ngx';


constructor(private qrScanner: QRScanner) { }

...

// Optionally request the permission early
this.qrScanner.prepare()
  .then((status: QRScannerStatus) => {
     if (status.authorized) {
       // camera permission was granted


       // start scanning
       let scanSub = this.qrScanner.scan().subscribe((text: string) => {
         console.log('Scanned something', text);

         this.qrScanner.hide(); // hide camera preview
         scanSub.unsubscribe(); // stop scanning
       });

     } else if (status.denied) {
       // camera permission was permanently denied
       // you must use QRScanner.openSettings() method to guide the user to the settings page
       // then they can grant the permission from there
     } else {
       // permission was denied, but not permanently. You can ask for permission again at a later time.
     }
  })
  .catch((e: any) => console.log('Error is', e));