BarcodeScanner Timeout

Hello community!

Is there any way to cancel a barcode scan after timeout? I found that sometimes some phones would not pick up the qr code for some reason (e.g. lens dirty, bad focus…) and I have the users trying and trying to scan without success and getting frustrated through the process.

So I am looking for an option to start the scan() function, then after, say 15 seconds pop up a message saying something like “having trouble?” and then provide some other option, for instance to enter a code manually or contact an operator or something.

Is there anything like that built in? Couldn’t find it in the docs.

Thanks a lot!

may be this link will useful :slight_smile:

Thanks! But no, I manage to scan successfully and everything works… as long as the phone can detect the code.

If the phone does not detect the code for a long time, it stays in the scan page forever. I was looking for a way to get out of scan mode after a while if no code was detected.

by the way $timeout automatically stop the execution when it not found data
have you use cancelled params in your result function?

I am not sure where to provide the $timeout you mention in the scan call. This is what I do:

            preferFrontCamera: false, // iOS and Android
            showFlipCameraButton: false, // iOS and Android
            showTorchButton: true, // iOS and Android
            torchOn: false, // Android, launch with the torch switched on (if available)
            resultDisplayDuration: 500,
            formats: 'QR_CODE,PDF_417'
      .then((data) => {
            // This happens when the QR was captured
      .catch((err) => {
             // This seems to happen only when the "back" button is pressed

So it is only cancelled when “back” is pressed. Is there any BarcodeScannerOptions to provide such $timeout that takes me to the “catch” after some time?

have you try $timeout function as given in this link ?

No, because I am not using AngularJS. I am using Ionic 2 with Angular2+ and Typescript