bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
568 stars 772 forks source link

THREAD WARNING: ['QRScanner'] took '468.501953' ms. Plugin should use a background thread. #121

Closed pbell89 closed 6 years ago

pbell89 commented 6 years ago

Hi there,

I'm having issues using the QR Scanner with Ionic.

ERROR OUTPUT:

THREAD WARNING: ['QRScanner'] took '468.501953' ms. Plugin should use a background thread.

App Module:

/src/app/app.module.ts

import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { QRScanner } from '@ionic-native/qr-scanner';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@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 {}

Markup

/pages/home/home.html

  <ion-navbar>
    <ion-title>
      App
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <button ion-button full (click)="scanTickets()">Scan Tickets</button>
</ion-content>

Home Typescript

/pages/home/home.ts

import { NavController, AlertController } 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, 
    public alertCtrl: AlertController,
    private qrScanner: QRScanner) {

  }

  scanTickets() {
    // 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
        });

        // show camera preview
        this.qrScanner.show();

        // wait for user to scan something, then the observable callback will be called

      } 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));
  } 
}
yusufcanb commented 6 years ago

+1

ThijmenDF commented 6 years ago

This happens for Cordova as well.

I got the message on an iPhone 5s THREAD WARNING: ['QRScanner'] took '10.020996' ms. Plugin should use a background thread.

MissMonacoin commented 6 years ago

I got the same error too. https://github.com/MissMonacoin/monya/blob/master/component/qrcode.js Making methods asynchronous may solve problem but how can i do it? is there asynchronous one? https://stackoverflow.com/questions/46242282/thread-warning-inappbrowser-took-175-479736-ms-plugin-should-use-a-backg

bitjson commented 6 years ago

PRs welcome!

There are some changes in 2.6.0 which may help here. If you're still having trouble, please feel free to open a new issue.

SebastianJordan commented 5 years ago

Hi @bitjson , I have the same error and I have version 2.6.0 and for iOS it enables the background mode like that error comes out

THREAD WARNING: ['QRScanner'] took '68.887695' ms. Plugin should use a background thread.

markusweb commented 5 years ago

Using Version 3.0.1 still the same error.

THREAD WARNING: ['QRScanner'] took '383.850830' ms. Plugin should use a background thread.

cymxiao commented 3 years ago

+1