From ae228200464023cf7fada8d483a3ed647bc864cc Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 3 Sep 2014 17:40:20 -0700 Subject: [PATCH] CB-4003 - Add config option to not use location information in Camera plugin (and default to not use it) --- doc/index.md | 9 ++++++++- plugin.xml | 1 + src/ios/CDVCamera.h | 1 + src/ios/CDVCamera.m | 36 +++++++++++++++++++++++------------- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/doc/index.md b/doc/index.md index 8429769..0ca141f 100644 --- a/doc/index.md +++ b/doc/index.md @@ -85,6 +85,13 @@ than `DATA_URL`. - Windows Phone 7 and 8 - Windows 8 +### Preferences (iOS) + +- __CameraUsesGeolocation__ (boolean, defaults to false). For capturing JPEGs, set to true to get geolocation data in the EXIF header. This will trigger a request for geolocation permissions if set to true. + + + + ### Amazon Fire OS Quirks Amazon Fire OS uses intents to launch the camera activity on the device to capture @@ -226,7 +233,7 @@ Optional parameters to customize the camera settings. FRONT : 1 // Use the front-facing camera }; -### Amazon Fire OSQuirks +### Amazon Fire OS Quirks - Any `cameraDirection` value results in a back-facing photo. diff --git a/plugin.xml b/plugin.xml index c9276e5..a124ee9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -126,6 +126,7 @@ + diff --git a/src/ios/CDVCamera.h b/src/ios/CDVCamera.h index 5d4a81d..c2a71ac 100644 --- a/src/ios/CDVCamera.h +++ b/src/ios/CDVCamera.h @@ -57,6 +57,7 @@ typedef NSUInteger CDVMediaType; @property (assign) bool cropToSize; @property (strong) UIView* webView; @property (assign) BOOL popoverSupported; +@property (assign) BOOL usesGeolocation; @end diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index ac20c39..c2409be 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -49,6 +49,13 @@ static NSSet* org_apache_cordova_validArrowDirections; @synthesize hasPendingOperation, pickerController, locationManager; + +- (BOOL)usesGeolocation +{ + id useGeo = [self.commandDelegate.settings objectForKey:[@"CameraUsesGeolocation" lowercaseString]]; + return [(NSNumber*)useGeo boolValue]; +} + - (BOOL)popoverSupported { return (NSClassFromString(@"UIPopoverController") != nil) && @@ -121,6 +128,7 @@ static NSSet* org_apache_cordova_validArrowDirections; // we need to capture this state for memory warnings that dealloc this object cameraPicker.webView = self.webView; cameraPicker.popoverSupported = [self popoverSupported]; + cameraPicker.usesGeolocation = [self usesGeolocation]; cameraPicker.correctOrientation = [[arguments objectAtIndex:8] boolValue]; cameraPicker.saveToPhotoAlbum = [[arguments objectAtIndex:9] boolValue]; @@ -306,20 +314,22 @@ static NSSet* org_apache_cordova_validArrowDirections; data = UIImageJPEGRepresentation(returnedImage, 1.0); } else { data = UIImageJPEGRepresentation(returnedImage, cameraPicker.quality / 100.0f); - - NSDictionary *controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"]; - if (controllerMetadata) { - self.data = data; - self.metadata = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary *EXIFDictionary = [[controllerMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy]; - if (EXIFDictionary) [self.metadata setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary]; - - if (IsAtLeastiOSVersion(@"8.0")) { - [[self locationManager] performSelector:NSSelectorFromString(@"requestWhenInUseAuthorization") withObject:nil afterDelay:0]; + + if (cameraPicker.usesGeolocation) { + NSDictionary *controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"]; + if (controllerMetadata) { + self.data = data; + self.metadata = [[NSMutableDictionary alloc] init]; + + NSMutableDictionary *EXIFDictionary = [[controllerMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy]; + if (EXIFDictionary) [self.metadata setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary]; + + if (IsAtLeastiOSVersion(@"8.0")) { + [[self locationManager] performSelector:NSSelectorFromString(@"requestWhenInUseAuthorization") withObject:nil afterDelay:0]; + } + [[self locationManager] startUpdatingLocation]; + return; } - [[self locationManager] startUpdatingLocation]; - return; } }