mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:35:10 +08:00
CB-12682: (ios, android): changes cancel error message to be consistent for ios android
This commit is contained in:
parent
1b218cd8a0
commit
c3d7e55ad4
@ -783,7 +783,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
}// If cancelled
|
}// If cancelled
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
this.failPicture("Camera cancelled.");
|
this.failPicture("No Image Selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If something else
|
// If something else
|
||||||
@ -812,7 +812,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
// If cancelled
|
// If cancelled
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
this.failPicture("Camera cancelled.");
|
this.failPicture("No Image Selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If something else
|
// If something else
|
||||||
@ -831,7 +831,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
this.failPicture("Selection cancelled.");
|
this.failPicture("No Image Selected");
|
||||||
} else {
|
} else {
|
||||||
this.failPicture("Selection did not complete!");
|
this.failPicture("Selection did not complete!");
|
||||||
}
|
}
|
||||||
@ -849,7 +849,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write an inputstream to local disk
|
* Write an inputstream to local disk
|
||||||
*
|
*
|
||||||
|
@ -42,7 +42,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString");
|
SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString");
|
||||||
SEL s2 = NSSelectorFromString(@"base64EncodedString");
|
SEL s2 = NSSelectorFromString(@"base64EncodedString");
|
||||||
SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:");
|
SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:");
|
||||||
|
|
||||||
if ([data respondsToSelector:s1]) {
|
if ([data respondsToSelector:s1]) {
|
||||||
NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1];
|
NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1];
|
||||||
return func(data, s1);
|
return func(data, s1);
|
||||||
@ -66,7 +66,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
pictureOptions.quality = [command argumentAtIndex:0 withDefault:@(50)];
|
pictureOptions.quality = [command argumentAtIndex:0 withDefault:@(50)];
|
||||||
pictureOptions.destinationType = [[command argumentAtIndex:1 withDefault:@(DestinationTypeFileUri)] unsignedIntegerValue];
|
pictureOptions.destinationType = [[command argumentAtIndex:1 withDefault:@(DestinationTypeFileUri)] unsignedIntegerValue];
|
||||||
pictureOptions.sourceType = [[command argumentAtIndex:2 withDefault:@(UIImagePickerControllerSourceTypeCamera)] unsignedIntegerValue];
|
pictureOptions.sourceType = [[command argumentAtIndex:2 withDefault:@(UIImagePickerControllerSourceTypeCamera)] unsignedIntegerValue];
|
||||||
|
|
||||||
NSNumber* targetWidth = [command argumentAtIndex:3 withDefault:nil];
|
NSNumber* targetWidth = [command argumentAtIndex:3 withDefault:nil];
|
||||||
NSNumber* targetHeight = [command argumentAtIndex:4 withDefault:nil];
|
NSNumber* targetHeight = [command argumentAtIndex:4 withDefault:nil];
|
||||||
pictureOptions.targetSize = CGSizeMake(0, 0);
|
pictureOptions.targetSize = CGSizeMake(0, 0);
|
||||||
@ -81,10 +81,10 @@ static NSString* toBase64(NSData* data) {
|
|||||||
pictureOptions.saveToPhotoAlbum = [[command argumentAtIndex:9 withDefault:@(NO)] boolValue];
|
pictureOptions.saveToPhotoAlbum = [[command argumentAtIndex:9 withDefault:@(NO)] boolValue];
|
||||||
pictureOptions.popoverOptions = [command argumentAtIndex:10 withDefault:nil];
|
pictureOptions.popoverOptions = [command argumentAtIndex:10 withDefault:nil];
|
||||||
pictureOptions.cameraDirection = [[command argumentAtIndex:11 withDefault:@(UIImagePickerControllerCameraDeviceRear)] unsignedIntegerValue];
|
pictureOptions.cameraDirection = [[command argumentAtIndex:11 withDefault:@(UIImagePickerControllerCameraDeviceRear)] unsignedIntegerValue];
|
||||||
|
|
||||||
pictureOptions.popoverSupported = NO;
|
pictureOptions.popoverSupported = NO;
|
||||||
pictureOptions.usesGeolocation = NO;
|
pictureOptions.usesGeolocation = NO;
|
||||||
|
|
||||||
return pictureOptions;
|
return pictureOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
- (NSURL*) urlTransformer:(NSURL*)url
|
- (NSURL*) urlTransformer:(NSURL*)url
|
||||||
{
|
{
|
||||||
NSURL* urlToTransform = url;
|
NSURL* urlToTransform = url;
|
||||||
|
|
||||||
// for backwards compatibility - we check if this property is there
|
// for backwards compatibility - we check if this property is there
|
||||||
SEL sel = NSSelectorFromString(@"urlTransformer");
|
SEL sel = NSSelectorFromString(@"urlTransformer");
|
||||||
if ([self.commandDelegate respondsToSelector:sel]) {
|
if ([self.commandDelegate respondsToSelector:sel]) {
|
||||||
@ -120,7 +120,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
urlToTransform = urlTransformer(url);
|
urlToTransform = urlTransformer(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlToTransform;
|
return urlToTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,16 +139,16 @@ static NSString* toBase64(NSData* data) {
|
|||||||
- (void)takePicture:(CDVInvokedUrlCommand*)command
|
- (void)takePicture:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
self.hasPendingOperation = YES;
|
self.hasPendingOperation = YES;
|
||||||
|
|
||||||
__weak CDVCamera* weakSelf = self;
|
__weak CDVCamera* weakSelf = self;
|
||||||
|
|
||||||
[self.commandDelegate runInBackground:^{
|
[self.commandDelegate runInBackground:^{
|
||||||
|
|
||||||
CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command];
|
CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command];
|
||||||
pictureOptions.popoverSupported = [weakSelf popoverSupported];
|
pictureOptions.popoverSupported = [weakSelf popoverSupported];
|
||||||
pictureOptions.usesGeolocation = [weakSelf usesGeolocation];
|
pictureOptions.usesGeolocation = [weakSelf usesGeolocation];
|
||||||
pictureOptions.cropToSize = NO;
|
pictureOptions.cropToSize = NO;
|
||||||
|
|
||||||
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:pictureOptions.sourceType];
|
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:pictureOptions.sourceType];
|
||||||
if (!hasCamera) {
|
if (!hasCamera) {
|
||||||
NSLog(@"Camera.getPicture: source type %lu not available.", (unsigned long)pictureOptions.sourceType);
|
NSLog(@"Camera.getPicture: source type %lu not available.", (unsigned long)pictureOptions.sourceType);
|
||||||
@ -184,12 +184,12 @@ static NSString* toBase64(NSData* data) {
|
|||||||
|
|
||||||
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
|
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
|
||||||
weakSelf.pickerController = cameraPicker;
|
weakSelf.pickerController = cameraPicker;
|
||||||
|
|
||||||
cameraPicker.delegate = weakSelf;
|
cameraPicker.delegate = weakSelf;
|
||||||
cameraPicker.callbackId = command.callbackId;
|
cameraPicker.callbackId = command.callbackId;
|
||||||
// we need to capture this state for memory warnings that dealloc this object
|
// we need to capture this state for memory warnings that dealloc this object
|
||||||
cameraPicker.webView = weakSelf.webView;
|
cameraPicker.webView = weakSelf.webView;
|
||||||
|
|
||||||
// Perform UI operations on the main thread
|
// Perform UI operations on the main thread
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
// If a popover is already open, close it; we only want one at a time.
|
// If a popover is already open, close it; we only want one at a time.
|
||||||
@ -291,7 +291,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
{
|
{
|
||||||
if([navigationController isKindOfClass:[UIImagePickerController class]]){
|
if([navigationController isKindOfClass:[UIImagePickerController class]]){
|
||||||
UIImagePickerController* cameraPicker = (UIImagePickerController*)navigationController;
|
UIImagePickerController* cameraPicker = (UIImagePickerController*)navigationController;
|
||||||
|
|
||||||
if(![cameraPicker.mediaTypes containsObject:(NSString*)kUTTypeImage]){
|
if(![cameraPicker.mediaTypes containsObject:(NSString*)kUTTypeImage]){
|
||||||
[viewController.navigationItem setTitle:NSLocalizedString(@"Videos", nil)];
|
[viewController.navigationItem setTitle:NSLocalizedString(@"Videos", nil)];
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
- (NSData*)processImage:(UIImage*)image info:(NSDictionary*)info options:(CDVPictureOptions*)options
|
- (NSData*)processImage:(UIImage*)image info:(NSDictionary*)info options:(CDVPictureOptions*)options
|
||||||
{
|
{
|
||||||
NSData* data = nil;
|
NSData* data = nil;
|
||||||
|
|
||||||
switch (options.encodingType) {
|
switch (options.encodingType) {
|
||||||
case EncodingTypePNG:
|
case EncodingTypePNG:
|
||||||
data = UIImagePNGRepresentation(image);
|
data = UIImagePNGRepresentation(image);
|
||||||
@ -364,18 +364,18 @@ static NSString* toBase64(NSData* data) {
|
|||||||
} else {
|
} else {
|
||||||
data = UIImageJPEGRepresentation(image, [options.quality floatValue] / 100.0f);
|
data = UIImageJPEGRepresentation(image, [options.quality floatValue] / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.usesGeolocation) {
|
if (options.usesGeolocation) {
|
||||||
NSDictionary* controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
|
NSDictionary* controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
|
||||||
if (controllerMetadata) {
|
if (controllerMetadata) {
|
||||||
self.data = data;
|
self.data = data;
|
||||||
self.metadata = [[NSMutableDictionary alloc] init];
|
self.metadata = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
NSMutableDictionary* EXIFDictionary = [[controllerMetadata objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
|
NSMutableDictionary* EXIFDictionary = [[controllerMetadata objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
|
||||||
if (EXIFDictionary) {
|
if (EXIFDictionary) {
|
||||||
[self.metadata setObject:EXIFDictionary forKey:(NSString*)kCGImagePropertyExifDictionary];
|
[self.metadata setObject:EXIFDictionary forKey:(NSString*)kCGImagePropertyExifDictionary];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsAtLeastiOSVersion(@"8.0")) {
|
if (IsAtLeastiOSVersion(@"8.0")) {
|
||||||
[[self locationManager] performSelector:NSSelectorFromString(@"requestWhenInUseAuthorization") withObject:nil afterDelay:0];
|
[[self locationManager] performSelector:NSSelectorFromString(@"requestWhenInUseAuthorization") withObject:nil afterDelay:0];
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,13 +396,13 @@ static NSString* toBase64(NSData* data) {
|
|||||||
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
|
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
|
||||||
NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by Apple (vs [NSFileManager defaultManager]) to be threadsafe
|
NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by Apple (vs [NSFileManager defaultManager]) to be threadsafe
|
||||||
NSString* filePath;
|
NSString* filePath;
|
||||||
|
|
||||||
// generate unique file name
|
// generate unique file name
|
||||||
int i = 1;
|
int i = 1;
|
||||||
do {
|
do {
|
||||||
filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, extension];
|
filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, extension];
|
||||||
} while ([fileMgr fileExistsAtPath:filePath]);
|
} while ([fileMgr fileExistsAtPath:filePath]);
|
||||||
|
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,13 +415,13 @@ static NSString* toBase64(NSData* data) {
|
|||||||
} else {
|
} else {
|
||||||
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.correctOrientation) {
|
if (options.correctOrientation) {
|
||||||
image = [image imageCorrectedForCaptureOrientation];
|
image = [image imageCorrectedForCaptureOrientation];
|
||||||
}
|
}
|
||||||
|
|
||||||
UIImage* scaledImage = nil;
|
UIImage* scaledImage = nil;
|
||||||
|
|
||||||
if ((options.targetSize.width > 0) && (options.targetSize.height > 0)) {
|
if ((options.targetSize.width > 0) && (options.targetSize.height > 0)) {
|
||||||
// if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
|
// if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
|
||||||
if (options.cropToSize) {
|
if (options.cropToSize) {
|
||||||
@ -430,7 +430,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
scaledImage = [image imageByScalingNotCroppingForSize:options.targetSize];
|
scaledImage = [image imageByScalingNotCroppingForSize:options.targetSize];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (scaledImage == nil ? image : scaledImage);
|
return (scaledImage == nil ? image : scaledImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,11 +472,11 @@ static NSString* toBase64(NSData* data) {
|
|||||||
image = [self retrieveImage:info options:options];
|
image = [self retrieveImage:info options:options];
|
||||||
NSData* data = [self processImage:image info:info options:options];
|
NSData* data = [self processImage:image info:info options:options];
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
||||||
NSString* extension = options.encodingType == EncodingTypePNG? @"png" : @"jpg";
|
NSString* extension = options.encodingType == EncodingTypePNG? @"png" : @"jpg";
|
||||||
NSString* filePath = [self tempFilePath:extension];
|
NSString* filePath = [self tempFilePath:extension];
|
||||||
NSError* err = nil;
|
NSError* err = nil;
|
||||||
|
|
||||||
// save file
|
// save file
|
||||||
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
|
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
|
||||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
|
||||||
@ -498,7 +498,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (saveToPhotoAlbum && image) {
|
if (saveToPhotoAlbum && image) {
|
||||||
ALAssetsLibrary* library = [ALAssetsLibrary new];
|
ALAssetsLibrary* library = [ALAssetsLibrary new];
|
||||||
[library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)(image.imageOrientation) completionBlock:nil];
|
[library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)(image.imageOrientation) completionBlock:nil];
|
||||||
@ -517,10 +517,10 @@ static NSString* toBase64(NSData* data) {
|
|||||||
{
|
{
|
||||||
__weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
|
__weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
|
||||||
__weak CDVCamera* weakSelf = self;
|
__weak CDVCamera* weakSelf = self;
|
||||||
|
|
||||||
dispatch_block_t invoke = ^(void) {
|
dispatch_block_t invoke = ^(void) {
|
||||||
__block CDVPluginResult* result = nil;
|
__block CDVPluginResult* result = nil;
|
||||||
|
|
||||||
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
|
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
|
||||||
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
|
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
|
||||||
[weakSelf resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) {
|
[weakSelf resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) {
|
||||||
@ -538,7 +538,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
weakSelf.pickerController = nil;
|
weakSelf.pickerController = nil;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cameraPicker.pictureOptions.popoverSupported && (cameraPicker.pickerPopoverController != nil)) {
|
if (cameraPicker.pictureOptions.popoverSupported && (cameraPicker.pickerPopoverController != nil)) {
|
||||||
[cameraPicker.pickerPopoverController dismissPopoverAnimated:YES];
|
[cameraPicker.pickerPopoverController dismissPopoverAnimated:YES];
|
||||||
cameraPicker.pickerPopoverController.delegate = nil;
|
cameraPicker.pickerPopoverController.delegate = nil;
|
||||||
@ -561,7 +561,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
{
|
{
|
||||||
__weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
|
__weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
|
||||||
__weak CDVCamera* weakSelf = self;
|
__weak CDVCamera* weakSelf = self;
|
||||||
|
|
||||||
dispatch_block_t invoke = ^ (void) {
|
dispatch_block_t invoke = ^ (void) {
|
||||||
CDVPluginResult* result;
|
CDVPluginResult* result;
|
||||||
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != ALAuthorizationStatusAuthorized) {
|
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != ALAuthorizationStatusAuthorized) {
|
||||||
@ -569,12 +569,12 @@ static NSString* toBase64(NSData* data) {
|
|||||||
} else if (picker.sourceType != UIImagePickerControllerSourceTypeCamera && [ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusAuthorized) {
|
} else if (picker.sourceType != UIImagePickerControllerSourceTypeCamera && [ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusAuthorized) {
|
||||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to assets"];
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to assets"];
|
||||||
} else {
|
} else {
|
||||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no image selected"];
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No Image Selected"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[weakSelf.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
|
[weakSelf.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
|
||||||
|
|
||||||
weakSelf.hasPendingOperation = NO;
|
weakSelf.hasPendingOperation = NO;
|
||||||
weakSelf.pickerController = nil;
|
weakSelf.pickerController = nil;
|
||||||
};
|
};
|
||||||
@ -587,11 +587,11 @@ static NSString* toBase64(NSData* data) {
|
|||||||
if (locationManager != nil) {
|
if (locationManager != nil) {
|
||||||
return locationManager;
|
return locationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
locationManager = [[CLLocationManager alloc] init];
|
locationManager = [[CLLocationManager alloc] init];
|
||||||
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
|
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
|
||||||
[locationManager setDelegate:self];
|
[locationManager setDelegate:self];
|
||||||
|
|
||||||
return locationManager;
|
return locationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,15 +600,15 @@ static NSString* toBase64(NSData* data) {
|
|||||||
if (locationManager == nil) {
|
if (locationManager == nil) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.locationManager stopUpdatingLocation];
|
[self.locationManager stopUpdatingLocation];
|
||||||
self.locationManager = nil;
|
self.locationManager = nil;
|
||||||
|
|
||||||
NSMutableDictionary *GPSDictionary = [[NSMutableDictionary dictionary] init];
|
NSMutableDictionary *GPSDictionary = [[NSMutableDictionary dictionary] init];
|
||||||
|
|
||||||
CLLocationDegrees latitude = newLocation.coordinate.latitude;
|
CLLocationDegrees latitude = newLocation.coordinate.latitude;
|
||||||
CLLocationDegrees longitude = newLocation.coordinate.longitude;
|
CLLocationDegrees longitude = newLocation.coordinate.longitude;
|
||||||
|
|
||||||
// latitude
|
// latitude
|
||||||
if (latitude < 0.0) {
|
if (latitude < 0.0) {
|
||||||
latitude = latitude * -1.0f;
|
latitude = latitude * -1.0f;
|
||||||
@ -617,7 +617,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
[GPSDictionary setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
|
[GPSDictionary setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
|
||||||
}
|
}
|
||||||
[GPSDictionary setObject:[NSNumber numberWithFloat:latitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
|
[GPSDictionary setObject:[NSNumber numberWithFloat:latitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
|
||||||
|
|
||||||
// longitude
|
// longitude
|
||||||
if (longitude < 0.0) {
|
if (longitude < 0.0) {
|
||||||
longitude = longitude * -1.0f;
|
longitude = longitude * -1.0f;
|
||||||
@ -627,7 +627,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
[GPSDictionary setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
|
[GPSDictionary setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
|
||||||
}
|
}
|
||||||
[GPSDictionary setObject:[NSNumber numberWithFloat:longitude] forKey:(NSString*)kCGImagePropertyGPSLongitude];
|
[GPSDictionary setObject:[NSNumber numberWithFloat:longitude] forKey:(NSString*)kCGImagePropertyGPSLongitude];
|
||||||
|
|
||||||
// altitude
|
// altitude
|
||||||
CGFloat altitude = newLocation.altitude;
|
CGFloat altitude = newLocation.altitude;
|
||||||
if (!isnan(altitude)){
|
if (!isnan(altitude)){
|
||||||
@ -639,7 +639,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
}
|
}
|
||||||
[GPSDictionary setObject:[NSNumber numberWithFloat:altitude] forKey:(NSString *)kCGImagePropertyGPSAltitude];
|
[GPSDictionary setObject:[NSNumber numberWithFloat:altitude] forKey:(NSString *)kCGImagePropertyGPSAltitude];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time and date
|
// Time and date
|
||||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||||
[formatter setDateFormat:@"HH:mm:ss.SSSSSS"];
|
[formatter setDateFormat:@"HH:mm:ss.SSSSSS"];
|
||||||
@ -647,7 +647,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
[GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp];
|
[GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp];
|
||||||
[formatter setDateFormat:@"yyyy:MM:dd"];
|
[formatter setDateFormat:@"yyyy:MM:dd"];
|
||||||
[GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp];
|
[GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp];
|
||||||
|
|
||||||
[self.metadata setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
|
[self.metadata setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
|
||||||
[self imagePickerControllerReturnImageResult];
|
[self imagePickerControllerReturnImageResult];
|
||||||
}
|
}
|
||||||
@ -660,7 +660,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
|
|
||||||
[self.locationManager stopUpdatingLocation];
|
[self.locationManager stopUpdatingLocation];
|
||||||
self.locationManager = nil;
|
self.locationManager = nil;
|
||||||
|
|
||||||
[self imagePickerControllerReturnImageResult];
|
[self imagePickerControllerReturnImageResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,26 +668,26 @@ static NSString* toBase64(NSData* data) {
|
|||||||
{
|
{
|
||||||
CDVPictureOptions* options = self.pickerController.pictureOptions;
|
CDVPictureOptions* options = self.pickerController.pictureOptions;
|
||||||
CDVPluginResult* result = nil;
|
CDVPluginResult* result = nil;
|
||||||
|
|
||||||
if (self.metadata) {
|
if (self.metadata) {
|
||||||
CGImageSourceRef sourceImage = CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL);
|
CGImageSourceRef sourceImage = CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL);
|
||||||
CFStringRef sourceType = CGImageSourceGetType(sourceImage);
|
CFStringRef sourceType = CGImageSourceGetType(sourceImage);
|
||||||
|
|
||||||
CGImageDestinationRef destinationImage = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)self.data, sourceType, 1, NULL);
|
CGImageDestinationRef destinationImage = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)self.data, sourceType, 1, NULL);
|
||||||
CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, (__bridge CFDictionaryRef)self.metadata);
|
CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, (__bridge CFDictionaryRef)self.metadata);
|
||||||
CGImageDestinationFinalize(destinationImage);
|
CGImageDestinationFinalize(destinationImage);
|
||||||
|
|
||||||
CFRelease(sourceImage);
|
CFRelease(sourceImage);
|
||||||
CFRelease(destinationImage);
|
CFRelease(destinationImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (options.destinationType) {
|
switch (options.destinationType) {
|
||||||
case DestinationTypeFileUri:
|
case DestinationTypeFileUri:
|
||||||
{
|
{
|
||||||
NSError* err = nil;
|
NSError* err = nil;
|
||||||
NSString* extension = self.pickerController.pictureOptions.encodingType == EncodingTypePNG ? @"png":@"jpg";
|
NSString* extension = self.pickerController.pictureOptions.encodingType == EncodingTypePNG ? @"png":@"jpg";
|
||||||
NSString* filePath = [self tempFilePath:extension];
|
NSString* filePath = [self tempFilePath:extension];
|
||||||
|
|
||||||
// save file
|
// save file
|
||||||
if (![self.data writeToFile:filePath options:NSAtomicWrite error:&err]) {
|
if (![self.data writeToFile:filePath options:NSAtomicWrite error:&err]) {
|
||||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
|
||||||
@ -706,16 +706,16 @@ static NSString* toBase64(NSData* data) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
[self.commandDelegate sendPluginResult:result callbackId:self.pickerController.callbackId];
|
[self.commandDelegate sendPluginResult:result callbackId:self.pickerController.callbackId];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.hasPendingOperation = NO;
|
self.hasPendingOperation = NO;
|
||||||
self.pickerController = nil;
|
self.pickerController = nil;
|
||||||
self.data = nil;
|
self.data = nil;
|
||||||
self.metadata = nil;
|
self.metadata = nil;
|
||||||
|
|
||||||
if (options.saveToPhotoAlbum) {
|
if (options.saveToPhotoAlbum) {
|
||||||
ALAssetsLibrary *library = [ALAssetsLibrary new];
|
ALAssetsLibrary *library = [ALAssetsLibrary new];
|
||||||
[library writeImageDataToSavedPhotosAlbum:self.data metadata:self.metadata completionBlock:nil];
|
[library writeImageDataToSavedPhotosAlbum:self.data metadata:self.metadata completionBlock:nil];
|
||||||
@ -735,14 +735,14 @@ static NSString* toBase64(NSData* data) {
|
|||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewWillAppear:(BOOL)animated
|
- (void)viewWillAppear:(BOOL)animated
|
||||||
{
|
{
|
||||||
SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate");
|
SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate");
|
||||||
if ([self respondsToSelector:sel]) {
|
if ([self respondsToSelector:sel]) {
|
||||||
[self performSelector:sel withObject:nil afterDelay:0];
|
[self performSelector:sel withObject:nil afterDelay:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
[super viewWillAppear:animated];
|
[super viewWillAppear:animated];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -752,7 +752,7 @@ static NSString* toBase64(NSData* data) {
|
|||||||
cameraPicker.pictureOptions = pictureOptions;
|
cameraPicker.pictureOptions = pictureOptions;
|
||||||
cameraPicker.sourceType = pictureOptions.sourceType;
|
cameraPicker.sourceType = pictureOptions.sourceType;
|
||||||
cameraPicker.allowsEditing = pictureOptions.allowsEditing;
|
cameraPicker.allowsEditing = pictureOptions.allowsEditing;
|
||||||
|
|
||||||
if (cameraPicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
if (cameraPicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
||||||
// We only allow taking pictures (no video) in this API.
|
// We only allow taking pictures (no video) in this API.
|
||||||
cameraPicker.mediaTypes = @[(NSString*)kUTTypeImage];
|
cameraPicker.mediaTypes = @[(NSString*)kUTTypeImage];
|
||||||
@ -764,8 +764,8 @@ static NSString* toBase64(NSData* data) {
|
|||||||
NSArray* mediaArray = @[(NSString*)(pictureOptions.mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage)];
|
NSArray* mediaArray = @[(NSString*)(pictureOptions.mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage)];
|
||||||
cameraPicker.mediaTypes = mediaArray;
|
cameraPicker.mediaTypes = mediaArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cameraPicker;
|
return cameraPicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user