From c3d7e55ad428bd154fa6bf5b2222cd38ee53b152 Mon Sep 17 00:00:00 2001 From: Sergii Stotskyi Date: Fri, 21 Apr 2017 14:08:37 +0300 Subject: [PATCH] CB-12682: (ios, android): changes cancel error message to be consistent for ios android --- src/android/CameraLauncher.java | 8 +-- src/ios/CDVCamera.m | 114 ++++++++++++++++---------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index b10f40f..c61121e 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -783,7 +783,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect }// If cancelled else if (resultCode == Activity.RESULT_CANCELED) { - this.failPicture("Camera cancelled."); + this.failPicture("No Image Selected"); } // If something else @@ -812,7 +812,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { - this.failPicture("Camera cancelled."); + this.failPicture("No Image Selected"); } // If something else @@ -831,7 +831,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect } }); } else if (resultCode == Activity.RESULT_CANCELED) { - this.failPicture("Selection cancelled."); + this.failPicture("No Image Selected"); } else { this.failPicture("Selection did not complete!"); } @@ -849,7 +849,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect return 0; } } - + /** * Write an inputstream to local disk * diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index 019141b..37b4ec8 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -42,7 +42,7 @@ static NSString* toBase64(NSData* data) { SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString"); SEL s2 = NSSelectorFromString(@"base64EncodedString"); SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:"); - + if ([data respondsToSelector:s1]) { NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1]; return func(data, s1); @@ -66,7 +66,7 @@ static NSString* toBase64(NSData* data) { pictureOptions.quality = [command argumentAtIndex:0 withDefault:@(50)]; pictureOptions.destinationType = [[command argumentAtIndex:1 withDefault:@(DestinationTypeFileUri)] unsignedIntegerValue]; pictureOptions.sourceType = [[command argumentAtIndex:2 withDefault:@(UIImagePickerControllerSourceTypeCamera)] unsignedIntegerValue]; - + NSNumber* targetWidth = [command argumentAtIndex:3 withDefault:nil]; NSNumber* targetHeight = [command argumentAtIndex:4 withDefault:nil]; pictureOptions.targetSize = CGSizeMake(0, 0); @@ -81,10 +81,10 @@ static NSString* toBase64(NSData* data) { pictureOptions.saveToPhotoAlbum = [[command argumentAtIndex:9 withDefault:@(NO)] boolValue]; pictureOptions.popoverOptions = [command argumentAtIndex:10 withDefault:nil]; pictureOptions.cameraDirection = [[command argumentAtIndex:11 withDefault:@(UIImagePickerControllerCameraDeviceRear)] unsignedIntegerValue]; - + pictureOptions.popoverSupported = NO; pictureOptions.usesGeolocation = NO; - + return pictureOptions; } @@ -109,7 +109,7 @@ static NSString* toBase64(NSData* data) { - (NSURL*) urlTransformer:(NSURL*)url { NSURL* urlToTransform = url; - + // for backwards compatibility - we check if this property is there SEL sel = NSSelectorFromString(@"urlTransformer"); if ([self.commandDelegate respondsToSelector:sel]) { @@ -120,7 +120,7 @@ static NSString* toBase64(NSData* data) { urlToTransform = urlTransformer(url); } } - + return urlToTransform; } @@ -139,16 +139,16 @@ static NSString* toBase64(NSData* data) { - (void)takePicture:(CDVInvokedUrlCommand*)command { self.hasPendingOperation = YES; - + __weak CDVCamera* weakSelf = self; [self.commandDelegate runInBackground:^{ - + CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command]; pictureOptions.popoverSupported = [weakSelf popoverSupported]; pictureOptions.usesGeolocation = [weakSelf usesGeolocation]; pictureOptions.cropToSize = NO; - + BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:pictureOptions.sourceType]; if (!hasCamera) { 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]; weakSelf.pickerController = cameraPicker; - + cameraPicker.delegate = weakSelf; cameraPicker.callbackId = command.callbackId; // we need to capture this state for memory warnings that dealloc this object cameraPicker.webView = weakSelf.webView; - + // Perform UI operations on the main thread dispatch_async(dispatch_get_main_queue(), ^{ // 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]]){ UIImagePickerController* cameraPicker = (UIImagePickerController*)navigationController; - + if(![cameraPicker.mediaTypes containsObject:(NSString*)kUTTypeImage]){ [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* data = nil; - + switch (options.encodingType) { case EncodingTypePNG: data = UIImagePNGRepresentation(image); @@ -364,18 +364,18 @@ static NSString* toBase64(NSData* data) { } else { data = UIImageJPEGRepresentation(image, [options.quality floatValue] / 100.0f); } - + if (options.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]; } @@ -387,7 +387,7 @@ static NSString* toBase64(NSData* data) { default: break; }; - + return data; } @@ -396,13 +396,13 @@ static NSString* toBase64(NSData* data) { NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by Apple (vs [NSFileManager defaultManager]) to be threadsafe NSString* filePath; - + // generate unique file name int i = 1; do { filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, extension]; } while ([fileMgr fileExistsAtPath:filePath]); - + return filePath; } @@ -415,13 +415,13 @@ static NSString* toBase64(NSData* data) { } else { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } - + if (options.correctOrientation) { image = [image imageCorrectedForCaptureOrientation]; } - + UIImage* scaledImage = nil; - + 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 (options.cropToSize) { @@ -430,7 +430,7 @@ static NSString* toBase64(NSData* data) { scaledImage = [image imageByScalingNotCroppingForSize:options.targetSize]; } } - + return (scaledImage == nil ? image : scaledImage); } @@ -472,11 +472,11 @@ static NSString* toBase64(NSData* data) { image = [self retrieveImage:info options:options]; NSData* data = [self processImage:image info:info options:options]; if (data) { - + NSString* extension = options.encodingType == EncodingTypePNG? @"png" : @"jpg"; NSString* filePath = [self tempFilePath:extension]; NSError* err = nil; - + // save file if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]]; @@ -498,7 +498,7 @@ static NSString* toBase64(NSData* data) { default: break; }; - + if (saveToPhotoAlbum && image) { ALAssetsLibrary* library = [ALAssetsLibrary new]; [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 CDVCamera* weakSelf = self; - + dispatch_block_t invoke = ^(void) { __block CDVPluginResult* result = nil; - + NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) { [weakSelf resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) { @@ -538,7 +538,7 @@ static NSString* toBase64(NSData* data) { weakSelf.pickerController = nil; } }; - + if (cameraPicker.pictureOptions.popoverSupported && (cameraPicker.pickerPopoverController != nil)) { [cameraPicker.pickerPopoverController dismissPopoverAnimated:YES]; cameraPicker.pickerPopoverController.delegate = nil; @@ -561,7 +561,7 @@ static NSString* toBase64(NSData* data) { { __weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker; __weak CDVCamera* weakSelf = self; - + dispatch_block_t invoke = ^ (void) { CDVPluginResult* result; 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) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to assets"]; } 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.hasPendingOperation = NO; weakSelf.pickerController = nil; }; @@ -587,11 +587,11 @@ static NSString* toBase64(NSData* data) { if (locationManager != nil) { return locationManager; } - + locationManager = [[CLLocationManager alloc] init]; [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; [locationManager setDelegate:self]; - + return locationManager; } @@ -600,15 +600,15 @@ static NSString* toBase64(NSData* data) { if (locationManager == nil) { return; } - + [self.locationManager stopUpdatingLocation]; self.locationManager = nil; - + NSMutableDictionary *GPSDictionary = [[NSMutableDictionary dictionary] init]; - + CLLocationDegrees latitude = newLocation.coordinate.latitude; CLLocationDegrees longitude = newLocation.coordinate.longitude; - + // latitude if (latitude < 0.0) { latitude = latitude * -1.0f; @@ -617,7 +617,7 @@ static NSString* toBase64(NSData* data) { [GPSDictionary setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef]; } [GPSDictionary setObject:[NSNumber numberWithFloat:latitude] forKey:(NSString*)kCGImagePropertyGPSLatitude]; - + // longitude if (longitude < 0.0) { longitude = longitude * -1.0f; @@ -627,7 +627,7 @@ static NSString* toBase64(NSData* data) { [GPSDictionary setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; } [GPSDictionary setObject:[NSNumber numberWithFloat:longitude] forKey:(NSString*)kCGImagePropertyGPSLongitude]; - + // altitude CGFloat altitude = newLocation.altitude; if (!isnan(altitude)){ @@ -639,7 +639,7 @@ static NSString* toBase64(NSData* data) { } [GPSDictionary setObject:[NSNumber numberWithFloat:altitude] forKey:(NSString *)kCGImagePropertyGPSAltitude]; } - + // Time and date NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss.SSSSSS"]; @@ -647,7 +647,7 @@ static NSString* toBase64(NSData* data) { [GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp]; [formatter setDateFormat:@"yyyy:MM:dd"]; [GPSDictionary setObject:[formatter stringFromDate:newLocation.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp]; - + [self.metadata setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary]; [self imagePickerControllerReturnImageResult]; } @@ -660,7 +660,7 @@ static NSString* toBase64(NSData* data) { [self.locationManager stopUpdatingLocation]; self.locationManager = nil; - + [self imagePickerControllerReturnImageResult]; } @@ -668,26 +668,26 @@ static NSString* toBase64(NSData* data) { { CDVPictureOptions* options = self.pickerController.pictureOptions; CDVPluginResult* result = nil; - + if (self.metadata) { CGImageSourceRef sourceImage = CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL); CFStringRef sourceType = CGImageSourceGetType(sourceImage); - + CGImageDestinationRef destinationImage = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)self.data, sourceType, 1, NULL); CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, (__bridge CFDictionaryRef)self.metadata); CGImageDestinationFinalize(destinationImage); - + CFRelease(sourceImage); CFRelease(destinationImage); } - + switch (options.destinationType) { case DestinationTypeFileUri: { NSError* err = nil; NSString* extension = self.pickerController.pictureOptions.encodingType == EncodingTypePNG ? @"png":@"jpg"; NSString* filePath = [self tempFilePath:extension]; - + // save file if (![self.data writeToFile:filePath options:NSAtomicWrite error:&err]) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]]; @@ -706,16 +706,16 @@ static NSString* toBase64(NSData* data) { default: break; }; - + if (result) { [self.commandDelegate sendPluginResult:result callbackId:self.pickerController.callbackId]; } - + self.hasPendingOperation = NO; self.pickerController = nil; self.data = nil; self.metadata = nil; - + if (options.saveToPhotoAlbum) { ALAssetsLibrary *library = [ALAssetsLibrary new]; [library writeImageDataToSavedPhotosAlbum:self.data metadata:self.metadata completionBlock:nil]; @@ -735,14 +735,14 @@ static NSString* toBase64(NSData* data) { { return nil; } - + - (void)viewWillAppear:(BOOL)animated { SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate"); if ([self respondsToSelector:sel]) { [self performSelector:sel withObject:nil afterDelay:0]; } - + [super viewWillAppear:animated]; } @@ -752,7 +752,7 @@ static NSString* toBase64(NSData* data) { cameraPicker.pictureOptions = pictureOptions; cameraPicker.sourceType = pictureOptions.sourceType; cameraPicker.allowsEditing = pictureOptions.allowsEditing; - + if (cameraPicker.sourceType == UIImagePickerControllerSourceTypeCamera) { // We only allow taking pictures (no video) in this API. cameraPicker.mediaTypes = @[(NSString*)kUTTypeImage]; @@ -764,8 +764,8 @@ static NSString* toBase64(NSData* data) { NSArray* mediaArray = @[(NSString*)(pictureOptions.mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage)]; cameraPicker.mediaTypes = mediaArray; } - + return cameraPicker; } -@end \ No newline at end of file +@end