capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 167 forks source link

Interpreting "Ask every time" as "denied" #284

Open mxavierneowrk opened 1 year ago

mxavierneowrk commented 1 year ago

Describe the bug On Android when asking for permission users has three options:

  1. Allow only while using the app
  2. Ask every time
  3. Don't allow

When users select the second option "Ask every time" we should ask every time if it allows, but it is assuming as "denied" directly.

To Reproduce Steps to reproduce the behavior:

  1. Ask users for permission
  2. Select the option "Ask every time"
  3. Close the app
  4. Go to app settings and change the permission to "Don't allow" and back to "Ask every time"
  5. Open the app again
  6. Ask users for permission

Expected behavior It should ask for permission again because the options selected is "Ask every time"

Current behavior The result comes straight as denied

Screenshots The option "Ask every time" is selected: image

When checking camera permissions it is returning denied as true: image

Version ^4.0.0

Smartphone:

Additional context This is the code that we are using:

public async cameraHasPermission(): Promise<boolean> {
        // check if user already granted permission
        const status = await BarcodeScanner.checkPermission({ force: true });

        alert(`{ force: true } -- Status: ${JSON.stringify(status)}`);

        if (status.granted) {
            // user granted permission
            return true;
        }

        if (status.denied) {
            // user denied permission
            await this.openCameraSettings();
            return false;
        }

        if (status.asked) {
            // system requested the user for permission during this call
            // only possible when force set to true
        }

        if (status.neverAsked) {
            // user has not been requested this permission before, we will prompt
            // a message asking for the permission
            const confirmed = confirm(await this.translationService.translateAsPromise(PermissionsTranslateKey.confirmCameraPermission));
            if (!confirmed) {
                await this.openCameraSettings();
                return false;
            }
        }

        if (status.restricted || status.unknown) {
            // ios only, probably means the permission has been denied
            await this.openCameraSettings();
            return false;
        }

        // user has not denied permission
        // but the user also has not yet granted the permission
        // so request it
        const statusRequest = await BarcodeScanner.checkPermission({ force: true });

        alert(`{ force: true } -- Status: ${JSON.stringify(statusRequest)}`);

        if (statusRequest.granted) {
            // the user did grant the permission now
            return true;
        }

        // user did not grant the permission, so he must have declined the request
        await this.openCameraSettings();
        return false;
    }
roboter commented 1 year ago

I have same bug First time user select ask every time everything is correct and scanner works second time no asking and blank screen, in logs I got "No Permission to use Camera"