为什么QR Scanner Ionic插件会生成错误?

时间:2018-08-21 16:51:14

标签: ios xcode ionic-framework ionic2 ionic3

编辑:我设法使该插件正常工作,但是当我在iPhone上测试该应用程序并单击该按钮时,Xcode会向我发送警告:THREAD WARNING: ['QRScanner'] took '468.501953' ms. Plugin should use a background thread


我尝试了很多事情,并遵循了许多文章和教程(也在此处,关于SO)来摆脱这一点。我正在使用此框架提供的QR Scanner插件来构建Ionic应用程序。我的app.module.ts是:

// Here are the basic Ionic import statements.
// Eventually, I import the plugin to scan QR codes.
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';

@NgModule({
  declarations: [ MyApp, HomePage ],
  imports: [ BrowserModule, IonicModule.forRoot(MyApp) ],
  bootstrap: [IonicApp],
  entryComponents: [ MyApp, HomePage ],
  providers: [ StatusBar, SplashScreen, QRScanner,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})

export class AppModule { }

文件夹结构为:

enter image description here

我的应用只有一页HomePagesrc/pages/home/home.ts文件的内容是:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';

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

export class HomePage {
  constructor(public navCtrl: NavController, private qrScanner: QRScanner) { }  
  scanQrCode() {
    this.qrScanner.prepare().then((status: QRScannerStatus) => {
      if (status.authorized) {
        let scanSub = this.qrScanner.scan().subscribe((text: string) => {             console.log('Scanned something', text); 
          this.qrScanner.hide();
          scanSub.unsubscribe();
        });
      } else if (status.denied) {
        // ...
      } else {
        // ...
      }
    }).catch((e: any) => console.log('Error is', e));
  }
}

src/pages/home/home.html文件中,我有:

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <button ion-button (click)="scanQrCode()"></button>
</ion-content>

我构建了该应用程序并在iPhone 5上运行它,但是当我单击按钮扫描代码时,Xcode会发送此消息:Error is [Object object]。你知道为什么吗?

0 个答案:

没有答案