EddyVerbruggen / nativescript-barcodescanner

🔎 NativeScript QR / barcode (bulk)scanner plugin
MIT License
293 stars 73 forks source link

ContinuousScanCallback not triggered after reopening app #234

Open Noppey opened 4 years ago

Noppey commented 4 years ago

I recently tried to switch to ContinuousScanCallback to resolve my scan result, instead of using the promise of barcodeScanner.scan itself.

When reading an QR code, this works fine the first time. But if I close and re-open my application, the ContinuousScanCallback doesn't get triggered anymore. I do here the scanning beep. There is also no resolve/reject occurring for the barcodeScanner.scan() promise.

Without continuouScanCallback everything works fine, I'm using the same QR code for testing all the time.

private doScan(): Promise<string> {
    return new Promise((resolve, reject) => {
      this.barcodeScanner.scan({
        presentInRootViewController: true, // not needed here, but added it just for show
        cancelLabel: localize('CLOSE'), // iOS only, default 'Close'
        cancelLabelBackgroundColor: "#333333", // iOS only, default '#000000' (black)
        message: localize('SCANQRCODE'), // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
        preferFrontCamera: false,     // Android only, default false
        showTorchButton: true,       // iOS only, default false
        torchOn: false,               // launch with the flashlight on (default false)
        resultDisplayDuration: 500,   // Android only, default 1500 (ms), set to 0 to disable echoing the scanned text
        orientation: 'portrait',     // Android only, default undefined (sensor-driven orientation), other options: portrait|landscape
        beepOnScan: true,             // Play or Suppress beep on scan (default true)
        fullScreen: true,             // iOS 13+ modal appearance changed so they can be swiped down when this is false (default false)
        openSettingsIfPermissionWasPreviouslyDenied: true // On iOS you can send the user to the settings app if access was previously denied
        continuousScanCallback: (result) => {
          console.log('result', result);
          if (result.text.split('|').length >= 3) {
            this.barcodeScanner.stop();
            resolve(result.text);
          }
        }
      }).then((result) => {
        console.log("then", result);
        resolve(result.text);
      }, () => {
        console.log('rejected');
        reject('error');
      });
    });
  }
EddyVerbruggen commented 4 years ago

Do you experience this on iOS/Android/both?

Noppey commented 4 years ago

Sorry it took me some time to test it on iOS as well through sidekick.

I only experience this on Android. It seems to work fine on iOS.

EddyVerbruggen commented 4 years ago

Would you mind testing the demo app in this repo? I tried to reproduce the problem with that app and failed (scanning remained working using the "unlimited scan, allow duplicates" option).

Instructions are at the top of the readme.

Noppey commented 4 years ago

Ok I've set the property reportDuplicates: true and now it works fine. Somehow it might still think it's in the same scanning session if I'm re-opening my application or something. I'm not sure what's going on.

Anyway, for me using reportDuplicates: true solves my problem, as I don't mind hitting continuousScanCallback for values multiple times given my code.

Noppey commented 4 years ago

I reproduced the issue on your application by removing reportDuplicates:true with npm run demo.android.

Click on unlimited scan, allow duplicates. Scan code once. Hit back. Scanner closed is logged. Click unlimited scan, allow duplicates again. Scan same code again. No results.

I would expect that hitting back (closing the scanner) and reopening would create a clean scanning session.

EddyVerbruggen commented 4 years ago

If I'm reading your tests correctly then I'd expect the setting of "allow duplicates" not to be relevant at all. I think that backbutton is somehow not cleaning up the previous session correctly. I wish I had time to look into it though.

Noppey commented 4 years ago

You're correct in the sense that it doesn't have influence on the session not being cleaned up. But obviously if you use continuousScanCallback with allow duplicates on, then it doesn't really matter if it's a new session or not.

Op di 18 feb. 2020 om 21:09 schreef Eddy Verbruggen < notifications@github.com>:

If I'm reading your tests correctly then I'd expect the setting of "allow duplicates" not to be relevant at all. I think that backbutton is somehow not cleaning up the previous session correctly. I wish I had time to look into it though.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/234?email_source=notifications&email_token=AC7HKH5LRZTVEX3IJ64PVX3RDQ6AJA5CNFSM4KWNIDSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMEJVII#issuecomment-587766433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7HKHZOUDCPOFUQBLKTQODRDQ6AJANCNFSM4KWNIDSA .