You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/05/12 02:25:44 UTC
cordova-plugin-camera git commit: CB-7667 iOS8: Handle case where
camera is not authorized (closes #49)
Repository: cordova-plugin-camera
Updated Branches:
refs/heads/master b8b53c625 -> 9f9e5ef4a
CB-7667 iOS8: Handle case where camera is not authorized (closes #49)
In iOS 7+, when the app does not have access to the camera, show a
prompt notifying the user so they're not puzzled by looking at a black
screen.
In iOS 8+, include a link on the dialog to open the Setting app to allow
the user to change their Camera privacy setting.
Signed-off-by: Shazron Abdullah <sh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/9f9e5ef4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/9f9e5ef4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/9f9e5ef4
Branch: refs/heads/master
Commit: 9f9e5ef4a9c5cf2a829e220ee627e7efc8110cd6
Parents: b8b53c6
Author: Dan Polivy <da...@cellartracker.com>
Authored: Tue Sep 30 14:28:24 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon May 11 17:26:00 2015 -0700
----------------------------------------------------------------------
plugin.xml | 1 +
src/ios/CDVCamera.m | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/9f9e5ef4/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 15a337c..25c1680 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -146,6 +146,7 @@
<framework src="AssetsLibrary.framework" />
<framework src="MobileCoreServices.framework" />
<framework src="CoreGraphics.framework" />
+ <framework src="AVFoundation.framework" />
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string></string>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/9f9e5ef4/src/ios/CDVCamera.m
----------------------------------------------------------------------
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 <ImageIO/CGImageProperties.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
#import <AssetsLibrary/AssetsLibrary.h>
+#import <AVFoundation/AVFoundation.h>
#import <ImageIO/CGImageSource.h>
#import <ImageIO/CGImageProperties.h>
#import <ImageIO/CGImageDestination.h>
@@ -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];
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org