Closed cindy-m closed 5 years ago
Hi, did you check the iOS source to see if you can find the cause? Happy to merge a PR as always!
Hi,
I have same issue with IOS, please try to use camera.requestCameraPermissions()
from nativescript-camera
instead of barcodescanner.requestCameraPermission()
@kefahB Good point, I'll take a look at their implementation and see if that can be applied to this plugin as well.
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;
}
}
});
};
Yep, I linked to that bit 😃- cheers mate!
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: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 theshowPermissionAlert
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 therequestCameraPermission
promise would only be resolved after the user grants or denies camera acces? Android works correctly as expected, this is only problem on iOS