question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS: requestCameraPermission resolved too early

See original GitHub issue

In our code, when the user uses the barcodescanner for the first time, we call the methode requestCameraPermission. Based on what the user choses, we either go to scan the code or show an alert that the permission was not granted for the functionality. The code looks like this:

this.barcodeScanner.requestCameraPermission()`
      .then(() => this._barcodeScanner.hasCameraPermission()) //workaround for Android
      .then((hasPermission: boolean) => {
        if (hasPermission) {
          this.scanQRCode();
        } else {
          this.showPermissionAlert();
        }
      })
      .catch(() => {
        this.showPermissionAlert();
      });

On iOS, it seems that the first time the user does get the alert with the question if he/she will grant camera acces, but in the code we saw with logging that the promise of the requestCameraPermission was already resolved and it is waiting in the showPermissionAlert function waiting till the alert is closed. So even when the user grants permission, he/she still will get the permission alert right after. Shouldn’t it be that the requestCameraPermission promise would only be resolved after the user grants or denies camera acces? Android works correctly as expected, this is only problem on iOS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EddyVerbruggencommented, Jun 7, 2019

Yep, I linked to that bit 😃- cheers mate!

1reaction
kefahBcommented, Jun 7, 2019

Here is it :

export let requestCameraPermissions = function () {
    return new Promise(function (resolve, reject) {
        let cameraStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo);
        switch (cameraStatus) {
            case AVAuthorizationStatus.NotDetermined: {
                AVCaptureDevice.requestAccessForMediaTypeCompletionHandler(AVMediaTypeVideo, (granted) => {
                    if (granted) {
                        resolve();
                    } else {
                        reject();
                    }
                });
                break;
            }
            case AVAuthorizationStatus.Authorized: {
                resolve();
                break;
            }
            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied: {
                if (trace.isEnabled()) {
                    trace.write("Application can not access Camera assets.", trace.categories.Debug);
                }
                reject();
                break;
            }
        }
    });
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to check if the user gave permission to use the camera?
@Esq: If your app already had the permission and set in the settings app, then it won't ask again. Check your settings app...
Read more >
Requesting Authorization for Media Capture on iOS
In iOS, the user must explicitly grant permission for each app to access cameras and microphones. Before your app can use the capture...
Read more >
Camera permission only requested on first load on ios #1470
On ios the camera permission is only requested on the first load, but after that the camera permission is not requested again. const ......
Read more >
How To FIX Allow Camera Access Not Working! (2022)
How To FIX Allow Camera Access Not Working! (2022). 12K views 8 months ago ... iPhone X In 2021: https://www.youtube.com/watch?v=f9wl8.
Read more >
Fixed: Allow Access to Camera Missing on iPhone Apps!
Unable to allow access to iPhone camera on apps like Instagram, Snapchat etc. because can't find the option? In this video we this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found