Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #302 from jcesarmobile/add-permission-check
Browse files Browse the repository at this point in the history
iOS: Added camera permission ckeck and fail if it's not permitted

Closes #301
  • Loading branch information
jcesarmobile committed Sep 6, 2016
2 parents 8004584 + 59301af commit 7dd0e84
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ios/CDVBarcodeScanner.mm
Expand Up @@ -138,6 +138,15 @@ - (NSString*)isScanNotPossible {
return result;
}

-(BOOL)notHasPermission
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
return (authStatus == AVAuthorizationStatusDenied ||
authStatus == AVAuthorizationStatusRestricted);
}



//--------------------------------------------------------------------------
- (void)scan:(CDVInvokedUrlCommand*)command {
CDVbcsProcessor* processor;
Expand All @@ -160,6 +169,10 @@ - (void)scan:(CDVInvokedUrlCommand*)command {
if (capabilityError) {
[self returnError:capabilityError callback:callback];
return;
} else if ([self notHasPermission]) {
NSString * error = NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.",nil);
[self returnError:error callback:callback];
return;
}

processor = [[CDVbcsProcessor alloc]
Expand Down

0 comments on commit 7dd0e84

Please sign in to comment.