diff --git a/plugin.xml b/plugin.xml
index 15a337c..25c1680 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -146,6 +146,7 @@
+
diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m
index 6521c9e..11ef17a 100644
--- a/src/ios/CDVCamera.m
+++ b/src/ios/CDVCamera.m
@@ -24,6 +24,7 @@
#import
#import
#import
+#import
#import
#import
#import
@@ -141,7 +142,29 @@ static NSString* toBase64(NSData* data) {
[weakSelf.commandDelegate sendPluginResult:result callbackId:command.callbackId];
return;
}
-
+
+ // Validate the app has permission to access the camera
+ if (pictureOptions.sourceType == UIImagePickerControllerSourceTypeCamera && [AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
+ AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
+ if (authStatus == AVAuthorizationStatusDenied ||
+ authStatus == AVAuthorizationStatusRestricted) {
+ // If iOS 8+, offer a link to the Settings app
+ NSString* settingsButton = (&UIApplicationOpenSettingsURLString != NULL)
+ ? NSLocalizedString(@"Settings", nil)
+ : nil;
+
+ // Denied; show an alert
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[[UIAlertView alloc] initWithTitle:[[NSBundle mainBundle]
+ objectForInfoDictionaryKey:@"CFBundleDisplayName"]
+ message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil)
+ delegate:self
+ cancelButtonTitle:NSLocalizedString(@"OK", nil)
+ otherButtonTitles:settingsButton, nil] show];
+ });
+ }
+ }
+
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
weakSelf.pickerController = cameraPicker;
@@ -174,6 +197,25 @@ static NSString* toBase64(NSData* data) {
}];
}
+// Delegate for camera permission UIAlertView
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ // If Settings button (on iOS 8), open the settings app
+ if (buttonIndex == 1) {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
+ }
+
+ // Dismiss the view
+ [[self.pickerController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
+
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to camera"]; // error callback expects string ATM
+
+ [self.commandDelegate sendPluginResult:result callbackId:self.pickerController.callbackId];
+
+ self.hasPendingOperation = NO;
+ self.pickerController = nil;
+}
+
- (void)repositionPopover:(CDVInvokedUrlCommand*)command
{
NSDictionary* options = [command argumentAtIndex:0 withDefault:nil];