From 376bec2b96699c32ef6d646e1c5aec954d12d3c9 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 11 Dec 2014 16:42:02 -0800 Subject: [PATCH] CB-8032 - Camera Plugin - Add nativeURL external method support for CDVFileSystem->makeEntryForPath:isDirectory: (closes #57) --- src/ios/CDVCamera.m | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index 857c9b1..290e350 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -30,6 +30,7 @@ #import #import #import +#import #define CDV_PHOTO_PREFIX @"cdv_photo_" @@ -84,6 +85,24 @@ static NSSet* org_apache_cordova_validArrowDirections; @synthesize hasPendingOperation, pickerController, locationManager; +- (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]) { + // grab the block from the commandDelegate + NSURL* (^urlTransformer)(NSURL*) = ((id(*)(id, SEL))objc_msgSend)(self.commandDelegate, sel); + // if block is not null, we call it + if (urlTransformer) { + urlToTransform = urlTransformer(url); + } + } + + return urlToTransform; +} + - (BOOL)usesGeolocation { id useGeo = [self.commandDelegate.settings objectForKey:[@"CameraUsesGeolocation" lowercaseString]]; @@ -336,7 +355,8 @@ static NSSet* org_apache_cordova_validArrowDirections; switch (options.destinationType) { case DestinationTypeNativeUri: { - NSString* nativeUri = [(NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString]; + NSURL* url = (NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL]; + NSString* nativeUri = [[self urlTransformer:url] absoluteString]; result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nativeUri]; saveToPhotoAlbum = NO; } @@ -355,7 +375,7 @@ static NSSet* org_apache_cordova_validArrowDirections; if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]]; } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[self urlTransformer:[NSURL fileURLWithPath:filePath]] absoluteString]]; } } } @@ -562,7 +582,7 @@ static NSSet* org_apache_cordova_validArrowDirections; result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]]; } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[self urlTransformer:[NSURL fileURLWithPath:filePath]] absoluteString]]; } } break;