incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/11] ios commit: Update core plugins to use commandDelegate::sendPluginResult
Date Thu, 04 Oct 2012 19:55:58 GMT
Updated Branches:
  refs/heads/master 1a4156931 -> 035e2fb9b


Update core plugins to use commandDelegate::sendPluginResult


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/035e2fb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/035e2fb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/035e2fb9

Branch: refs/heads/master
Commit: 035e2fb9bc76052a54f12b71648daba980af08fa
Parents: 780be09
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Oct 4 14:06:55 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Oct 4 15:51:43 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAccelerometer.m |    8 +-
 CordovaLib/Classes/CDVBattery.m       |    4 +-
 CordovaLib/Classes/CDVCamera.m        |   38 ++----
 CordovaLib/Classes/CDVCapture.h       |    8 +-
 CordovaLib/Classes/CDVCapture.m       |   87 +++++--------
 CordovaLib/Classes/CDVConnection.m    |   14 +--
 CordovaLib/Classes/CDVContacts.m      |   44 ++-----
 CordovaLib/Classes/CDVDevice.m        |    3 +-
 CordovaLib/Classes/CDVFile.h          |    2 +-
 CordovaLib/Classes/CDVFile.m          |  191 ++++++++--------------------
 CordovaLib/Classes/CDVFileTransfer.m  |   47 +++-----
 CordovaLib/Classes/CDVLocalStorage.m  |   10 +-
 CordovaLib/Classes/CDVLocation.m      |   35 ++---
 CordovaLib/Classes/CDVNotification.m  |   14 +-
 CordovaLib/Classes/CDVSound.m         |   37 +++---
 15 files changed, 181 insertions(+), 361 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVAccelerometer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAccelerometer.m b/CordovaLib/Classes/CDVAccelerometer.m
index 32471db..33093d0 100644
--- a/CordovaLib/Classes/CDVAccelerometer.m
+++ b/CordovaLib/Classes/CDVAccelerometer.m
@@ -95,9 +95,6 @@
 
 - (void)returnAccelInfo
 {
-    CDVPluginResult* result = nil;
-    NSString* jsString = nil;
-
     // Create an acceleration object
     NSMutableDictionary* accelProps = [NSMutableDictionary dictionaryWithCapacity:4];
 
@@ -106,10 +103,9 @@
     [accelProps setValue:[NSNumber numberWithDouble:z * kGravitationalConstant] forKey:@"z"];
     [accelProps setValue:[NSNumber numberWithDouble:timestamp] forKey:@"timestamp"];
 
-    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:accelProps];
+    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:accelProps];
     [result setKeepCallback:[NSNumber numberWithBool:YES]];
-    jsString = [result toSuccessCallbackString:self.callbackId];
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
 }
 
 // TODO: Consider using filtering to isolate instantaneous data vs. gravity data -jm

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVBattery.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVBattery.m b/CordovaLib/Classes/CDVBattery.m
index 53d7d90..681511c 100644
--- a/CordovaLib/Classes/CDVBattery.m
+++ b/CordovaLib/Classes/CDVBattery.m
@@ -64,7 +64,7 @@
     if (self.callbackId) {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:batteryData];
         [result setKeepCallbackAsBool:YES];
-        [super writeJavascript:[result toSuccessCallbackString:self.callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
     }
 }
 
@@ -121,7 +121,7 @@
     if (self.callbackId) {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self getBatteryStatus]];
         [result setKeepCallbackAsBool:NO];
-        [super writeJavascript:[result toSuccessCallbackString:self.callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
     }
     self.callbackId = nil;
     [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 84fde0f..33338bd 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -77,8 +77,8 @@ static NSSet* org_apache_cordova_validArrowDirections;
     bool hasCamera = [UIImagePickerController isSourceTypeAvailable:sourceType];
     if (!hasCamera) {
         NSLog(@"Camera.getPicture: source type %d not available.", sourceType);
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"no camera available"];
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no camera available"];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
         return;
     }
 
@@ -162,8 +162,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
 
 - (void)cleanup:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // empty the tmp directory
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
     NSError* err = nil;
@@ -188,13 +186,13 @@ static NSSet* org_apache_cordova_validArrowDirections;
         }
     }
 
+    CDVPluginResult* pluginResult;
     if (hasErrors) {
-        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:@"One or more files failed to be deleted."];
-        [super writeJavascript:[pluginResult toErrorCallbackString:callbackId]];
+        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:@"One or more files failed to be deleted."];
     } else {
-        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
-        [super writeJavascript:[pluginResult toSuccessCallbackString:callbackId]];
+        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
     }
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
 }
 
 - (void)popoverControllerDidDismissPopover:(id)popoverController
@@ -207,10 +205,8 @@ static NSSet* org_apache_cordova_validArrowDirections;
     if (self.pickerController && self.pickerController.callbackId && self.pickerController.popoverController) {
         self.pickerController.popoverController = nil;
         NSString* callbackId = self.pickerController.callbackId;
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"no image selected"];   // error callback expects string ATM
-        // this "delay hack" is in case the callback contains a JavaScript alert. Without this delay or a
-        // setTimeout("alert('fail');", 0) on the JS side, the app will hang when the alert is displayed.
-        [self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[result toErrorCallbackString:callbackId] afterDelay:0.5];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no image selected"];   // error callback expects string ATM
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
     self.hasPendingOperation = NO;
 }
@@ -219,8 +215,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
 {
     CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
 
-    NSString* callbackId = cameraPicker.callbackId;
-
     if (cameraPicker.popoverSupported && (cameraPicker.popoverController != nil)) {
         [cameraPicker.popoverController dismissPopoverAnimated:YES];
         cameraPicker.popoverController.delegate = nil;
@@ -233,7 +227,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
         }
     }
 
-    NSString* jsString = nil;
     CDVPluginResult* result = nil;
 
     NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
@@ -290,26 +283,22 @@ static NSSet* org_apache_cordova_validArrowDirections;
 
             // save file
             if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[err localizedDescription]];
-                jsString = [result toErrorCallbackString:callbackId];
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
             } else {
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
-                jsString = [result toSuccessCallbackString:callbackId];
             }
         } else {
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
-            jsString = [result toSuccessCallbackString:callbackId];
         }
     }
     // NOT IMAGE TYPE (MOVIE)
     else {
         NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:moviePath];
-        jsString = [result toSuccessCallbackString:callbackId];
     }
 
-    if (jsString) {
-        [self.webView stringByEvaluatingJavaScriptFromString:jsString];
+    if (result) {
+        [self.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
     }
 
     self.hasPendingOperation = NO;
@@ -341,7 +330,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
 - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
 {
     CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
-    NSString* callbackId = cameraPicker.callbackId;
 
     if ([cameraPicker respondsToSelector:@selector(presentingViewController)]) {
         [[cameraPicker presentingViewController] dismissModalViewControllerAnimated:YES];
@@ -350,8 +338,8 @@ static NSSet* org_apache_cordova_validArrowDirections;
     }
     // popoverControllerDidDismissPopover:(id)popoverController is called if popover is cancelled
 
-    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"no image selected"];   // error callback expects string ATM
-    [cameraPicker.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString:callbackId]];
+    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no image selected"];   // error callback expects string ATM
+    [self.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
 
     self.hasPendingOperation = NO;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVCapture.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCapture.h b/CordovaLib/Classes/CDVCapture.h
index 3ac73bd..afb82b4 100644
--- a/CordovaLib/Classes/CDVCapture.h
+++ b/CordovaLib/Classes/CDVCapture.h
@@ -52,9 +52,9 @@ typedef NSUInteger CDVCaptureError;
 @property BOOL inUse;
 - (void)captureAudio:(CDVInvokedUrlCommand*)command;
 - (void)captureImage:(CDVInvokedUrlCommand*)command;
-- (NSString*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId;
+- (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId;
 - (void)captureVideo:(CDVInvokedUrlCommand*)command;
-- (NSString*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId;
+- (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId;
 - (void)getMediaModes:(CDVInvokedUrlCommand*)command;
 - (void)getFormatData:(CDVInvokedUrlCommand*)command;
 - (NSDictionary*)getMediaDictionaryFromPath:(NSString*)fullPath ofType:(NSString*)type;
@@ -89,7 +89,7 @@ typedef NSUInteger CDVCaptureError;
     UILabel* timerLabel;
     AVAudioRecorder* avRecorder;
     AVAudioSession* avSession;
-    NSString* resultString;
+    CDVPluginResult* pluginResult;
     NSTimer* timer;
     BOOL isTimed;
 }
@@ -105,7 +105,7 @@ typedef NSUInteger CDVCaptureError;
 @property (nonatomic, strong) UILabel* timerLabel;
 @property (nonatomic, strong) AVAudioRecorder* avRecorder;
 @property (nonatomic, strong) AVAudioSession* avSession;
-@property (nonatomic, strong) NSString* resultString;
+@property (nonatomic, strong) CDVPluginResult* pluginResult;
 @property (nonatomic, strong) NSTimer* timer;
 @property (nonatomic) BOOL isTimed;
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVCapture.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCapture.m b/CordovaLib/Classes/CDVCapture.m
index 08c5006..43b14b2 100644
--- a/CordovaLib/Classes/CDVCapture.m
+++ b/CordovaLib/Classes/CDVCapture.m
@@ -77,9 +77,9 @@
     CDVPluginResult* result = nil;
 
     if (NSClassFromString(@"AVAudioRecorder") == nil) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_NOT_SUPPORTED];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
     } else if (self.inUse == YES) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_APPLICATION_BUSY];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_APPLICATION_BUSY];
     } else {
         // all the work occurs here
         CDVAudioRecorderViewController* audioViewController = [[CDVAudioRecorderViewController alloc] initWithCommand:self duration:duration callbackId:callbackId];
@@ -97,7 +97,7 @@
     }
 
     if (result) {
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -117,8 +117,8 @@
 
     if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
         NSLog(@"Capture.imageCapture: camera not available.");
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_NOT_SUPPORTED];
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         if (pickerController == nil) {
             pickerController = [[CDVImagePicker alloc] init];
@@ -154,14 +154,10 @@
  * IN:
  *  UIImage* image - the UIImage data returned from the camera
  *  NSString* callbackId
- * OUT:
- *  NSString* jsString - the error or success JavaScript string to execute
- *
  */
-- (NSString*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId
+- (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId
 {
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     // save the image to photo album
     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
@@ -186,8 +182,7 @@
     } while ([fileMgr fileExistsAtPath:filePath]);
 
     if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_INTERNAL_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
         if (err) {
             NSLog(@"Error saving image: %@", [err localizedDescription]);
         }
@@ -198,10 +193,9 @@
         NSArray* fileArray = [NSArray arrayWithObject:fileDict];
 
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
-        jsString = [result toSuccessCallbackString:callbackId];
     }
 
-    return jsString;
+    return result;
 }
 
 - (void)captureVideo:(CDVInvokedUrlCommand*)command
@@ -237,8 +231,8 @@
     if (!mediaType) {
         // don't have video camera return error
         NSLog(@"Capture.captureVideo: video mode not available.");
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_NOT_SUPPORTED];
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         pickerController.delegate = self;
         pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
@@ -271,11 +265,8 @@
     }
 }
 
-- (NSString*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId
+- (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId
 {
-    CDVPluginResult* result = nil;
-    NSString* jsString = nil;
-
     // save the movie to photo album (only avail as of iOS 3.1)
 
     /* don't need, it should automatically get saved
@@ -289,11 +280,7 @@
     NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil];
     NSArray* fileArray = [NSArray arrayWithObject:fileDict];
 
-    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
-    jsString = [result toSuccessCallbackString:callbackId];
-
-    //
-    return jsString;
+    return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
 }
 
 - (void)getMediaModes:(CDVInvokedUrlCommand*)command
@@ -342,7 +329,7 @@
         audioArray ? (NSObject*)                          audioArray:[NSNull null], @"audio",
         nil];
     NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", [modes cdvjk_JSONString]];
-    [self writeJavascript:jsString];
+    [self.commandDelegate evalJs:jsString];
 }
 
 - (void)getFormatData:(CDVInvokedUrlCommand*)command
@@ -359,7 +346,6 @@
     BOOL bError = NO;
     CDVCaptureError errorCode = CAPTURE_INTERNAL_ERR;
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     if (!mimeType || [mimeType isKindOfClass:[NSNull class]]) {
         // try to determine mime type if not provided
@@ -422,15 +408,13 @@
             }
         }
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:formatData];
-        jsString = [result toSuccessCallbackString:callbackId];
         // NSLog(@"getFormatData: %@", [formatData description]);
     }
     if (bError) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:errorCode];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:errorCode];
     }
-    if (jsString) {
-        [self writeJavascript:jsString];
+    if (result) {
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -485,7 +469,6 @@
         [[picker parentViewController] dismissModalViewControllerAnimated:YES];
     }
 
-    NSString* jsString = nil;
     CDVPluginResult* result = nil;
 
     UIImage* image = nil;
@@ -501,20 +484,18 @@
     }
     if (image != nil) {
         // mediaType was image
-        jsString = [self processImage:image type:cameraPicker.mimeType forCallbackId:callbackId];
+        result = [self processImage:image type:cameraPicker.mimeType forCallbackId:callbackId];
     } else if ([mediaType isEqualToString:(NSString*)kUTTypeMovie]) {
         // process video
         NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
         if (moviePath) {
-            jsString = [self processVideo:moviePath forCallbackId:callbackId];
+            result = [self processVideo:moviePath forCallbackId:callbackId];
         }
     }
-    if (!jsString) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_INTERNAL_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+    if (!result) {
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_INTERNAL_ERR];
     }
-
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
 - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
@@ -528,12 +509,8 @@
         [[picker parentViewController] dismissModalViewControllerAnimated:YES];
     }
 
-    NSString* jsString = nil;
-    CDVPluginResult* result = nil;
-    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_NO_MEDIA_FILES];
-    jsString = [result toErrorCallbackString:callbackId];
-
-    [self writeJavascript:jsString];
+    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NO_MEDIA_FILES];
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
 @end
@@ -549,7 +526,7 @@
 @end
 
 @implementation CDVAudioRecorderViewController
-@synthesize errorCode, callbackId, duration, captureCommand, doneButton, recordingView, recordButton, recordImage, stopRecordImage, timerLabel, avRecorder, avSession, resultString, timer, isTimed;
+@synthesize errorCode, callbackId, duration, captureCommand, doneButton, recordingView, recordButton, recordImage, stopRecordImage, timerLabel, avRecorder, avSession, pluginResult, timer, isTimed;
 
 - (NSString*)resolveImageResource:(NSString*)resource
 {
@@ -791,10 +768,9 @@
         [[self.captureCommand.viewController.modalViewController parentViewController] dismissModalViewControllerAnimated:YES];
     }
 
-    if (!self.resultString) {
+    if (!self.pluginResult) {
         // return error
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:self.errorCode];
-        self.resultString = [result toErrorCallbackString:callbackId];
+        self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:self.errorCode];
     }
 
     self.avRecorder = nil;
@@ -803,7 +779,7 @@
     [self.captureCommand setInUse:NO];
     UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
     // return result
-    [self.captureCommand writeJavascript:resultString];
+    [self.captureCommand.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
 }
 
 - (void)updateTime
@@ -838,11 +814,9 @@
         NSDictionary* fileDict = [captureCommand getMediaDictionaryFromPath:filePath ofType:@"audio/wav"];
         NSArray* fileArray = [NSArray arrayWithObject:fileDict];
 
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
-        self.resultString = [result toSuccessCallbackString:callbackId];
+        self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
     } else {
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_INTERNAL_ERR];
-        self.resultString = [result toErrorCallbackString:callbackId];
+        self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
     }
 }
 
@@ -852,8 +826,7 @@
     [self stopRecordingCleanup];
 
     NSLog(@"error recording audio");
-    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_INTERNAL_ERR];
-    self.resultString = [result toErrorCallbackString:callbackId];
+    self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
     [self dismissAudioView:nil];
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVConnection.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConnection.m b/CordovaLib/Classes/CDVConnection.m
index 9a7b392..0223a3a 100644
--- a/CordovaLib/Classes/CDVConnection.m
+++ b/CordovaLib/Classes/CDVConnection.m
@@ -30,13 +30,9 @@
 
 - (void)getConnectionInfo:(CDVInvokedUrlCommand*)command
 {
-    CDVPluginResult* result = nil;
-    NSString* jsString = nil;
-    NSString* callbackId = command.callbackId;
+    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType];
 
-    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType];
-    jsString = [result toSuccessCallbackString:callbackId];
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
@@ -80,7 +76,7 @@
     NSString* js = nil;
     // write the connection type
     js = [NSString stringWithFormat:@"navigator.network.connection.type = '%@';", self.connectionType];
-    [super writeJavascript:js];
+    [self.commandDelegate evalJs:js];
 
     // send "online"/"offline" event
     [self updateOnlineStatus];
@@ -102,9 +98,9 @@
     BOOL online = (status == ReachableViaWiFi) || (status == ReachableViaWWAN);
 
     if (online) {
-        [super writeJavascript:@"cordova.fireDocumentEvent('online');"];
+        [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('online');"];
     } else {
-        [super writeJavascript:@"cordova.fireDocumentEvent('offline');"];
+        [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('offline');"];
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVContacts.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContacts.m b/CordovaLib/Classes/CDVContacts.m
index 012a908..62f4080 100644
--- a/CordovaLib/Classes/CDVContacts.m
+++ b/CordovaLib/Classes/CDVContacts.m
@@ -127,8 +127,7 @@ dispatch_queue_t workQueue = nil;
     }
 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:recordId];
-    // jsString = [NSString stringWithFormat: @"%@(%d);", newCP.jsCallback, recordId];
-    [self writeJavascript:[result toSuccessCallbackString:callbackId]];
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
 - (void)displayContact:(CDVInvokedUrlCommand*)command
@@ -137,7 +136,7 @@ dispatch_queue_t workQueue = nil;
     ABRecordID recordID = [[command.arguments objectAtIndex:0] intValue];
     NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:[NSNull null]];
 
-    bool bEdit = [options isKindOfClass:[NSNull class]] ? false :[options existsValue:@"true" forKey:@"allowsEditing"];
+    bool bEdit = [options isKindOfClass:[NSNull class]] ? false : [options existsValue:@"true" forKey:@"allowsEditing"];
     ABAddressBookRef addrBook = ABAddressBookCreate();
     ABRecordRef rec = ABAddressBookGetPersonWithRecordID(addrBook, recordID);
 
@@ -169,8 +168,8 @@ dispatch_queue_t workQueue = nil;
         }
     } else {
         // no record, return error
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:UNKNOWN_ERROR];
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:UNKNOWN_ERROR];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
     CFRelease(addrBook);
 }
@@ -224,7 +223,7 @@ dispatch_queue_t workQueue = nil;
         picker.pickedContactDictionary = [pickedContact toDictionary:returnFields];
 
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:picker.pickedContactDictionary];
-        [self writeJavascript:[result toSuccessCallbackString:picker.callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:picker.callbackId];
 
         if ([picker respondsToSelector:@selector(presentingViewController)]) {
             [[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
@@ -257,7 +256,7 @@ dispatch_queue_t workQueue = nil;
         CFRelease(addrBook);
     }
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:picker.pickedContactDictionary];
-    [self writeJavascript:[result toSuccessCallbackString:picker.callbackId]];
+    [self.commandDelegate sendPluginResult:result callbackId:picker.callbackId];
 
     if ([peoplePicker respondsToSelector:@selector(presentingViewController)]) {
         [[peoplePicker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
@@ -278,7 +277,6 @@ dispatch_queue_t workQueue = nil;
             // more details here: http: //blog.byadrian.net/2012/05/05/ios-addressbook-framework-and-gcd/
             ABAddressBookRef addrBook = ABAddressBookCreate ();
 
-            NSString* jsString = nil;
             NSArray* foundRecords = nil;
             // get the findOptions values
             BOOL multiple = NO; // default is false
@@ -303,7 +301,7 @@ dispatch_queue_t workQueue = nil;
                 if (foundRecords && [foundRecords count] > 0) {
                     // create Contacts and put into matches array
                     // doesn't make sense to ask for all records when multiple == NO but better check
-                    int xferCount = multiple == YES ?[foundRecords count] : 1;
+                    int xferCount = multiple == YES ? [foundRecords count] : 1;
                     matches = [NSMutableArray arrayWithCapacity:xferCount];
 
                     for (int k = 0; k < xferCount; k++) {
@@ -335,7 +333,7 @@ dispatch_queue_t workQueue = nil;
                 // convert to JS Contacts format and return in callback
                 // - returnFields  determines what properties to return
                 @autoreleasepool {
-                    int count = multiple == YES ?[matches count] : 1;
+                    int count = multiple == YES ? [matches count] : 1;
 
                     for (int i = 0; i < count; i++) {
                         CDVContact* newContact = [matches objectAtIndex:i];
@@ -344,17 +342,11 @@ dispatch_queue_t workQueue = nil;
                     }
                 }
             }
-            CDVPluginResult* result = nil;
             // return found contacts (array is empty if no contacts found)
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:returnContacts];
-            jsString = [result toSuccessCallbackString:callbackId];
+            CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:returnContacts];
+            [self.commandDelegate sendPluginResult:result callbackId:callbackId];
             // NSLog(@"findCallback string: %@", jsString);
 
-            if (jsString) {
-                dispatch_async (dispatch_get_main_queue (), ^{
-                        [self writeJavascript:jsString];
-                    });
-            }
             if (addrBook) {
                 CFRelease (addrBook);
             }
@@ -369,7 +361,6 @@ dispatch_queue_t workQueue = nil;
     NSDictionary* contactDict = [command.arguments objectAtIndex:0];
 
     dispatch_async([CDVContacts getWorkQueue], ^{
-            NSString* jsString = nil;
             bool bIsError = FALSE, bSuccess = FALSE;
             BOOL bUpdate = NO;
             CDVContactError errCode = UNKNOWN_ERROR;
@@ -409,7 +400,6 @@ dispatch_queue_t workQueue = nil;
                     NSDictionary* newContact = [aContact toDictionary:[CDVContact defaultFields]];
                     // NSString* contactStr = [newContact JSONRepresentation];
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newContact];
-                    jsString = [result toSuccessCallbackString:callbackId];
                 }
             } else {
                 bIsError = TRUE;
@@ -419,13 +409,10 @@ dispatch_queue_t workQueue = nil;
 
             if (bIsError) {
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errCode];
-                jsString = [result toErrorCallbackString:callbackId];
             }
 
-            if (jsString) {
-                dispatch_async (dispatch_get_main_queue (), ^{
-                        [self writeJavascript:jsString];
-                    });
+            if (result) {
+                [self.commandDelegate sendPluginResult:result callbackId:callbackId];
             }
         }); // end of  queue
 }
@@ -434,7 +421,6 @@ dispatch_queue_t workQueue = nil;
 {
     NSString* callbackId = command.callbackId;
     NSNumber* cId = [command.arguments objectAtIndex:0];
-    NSString* jsString = nil;
     bool bIsError = FALSE, bSuccess = FALSE;
     CDVContactError errCode = UNKNOWN_ERROR;
     CFErrorRef error;
@@ -462,7 +448,6 @@ dispatch_queue_t workQueue = nil;
                     // [contactDict setObject:[NSNull null] forKey:kW3ContactId];
                     // result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: contactDict];
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
-                    jsString = [result toSuccessCallbackString:callbackId];
                     // NSString* contactStr = [contactDict JSONRepresentation];
                 }
             }
@@ -482,10 +467,9 @@ dispatch_queue_t workQueue = nil;
     }
     if (bIsError) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errCode];
-        jsString = [result toErrorCallbackString:callbackId];
     }
-    if (jsString) {
-        [self writeJavascript:jsString];
+    if (result) {
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 
     return;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVDevice.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVDevice.m b/CordovaLib/Classes/CDVDevice.m
index 0b8f026..879868c 100644
--- a/CordovaLib/Classes/CDVDevice.m
+++ b/CordovaLib/Classes/CDVDevice.m
@@ -26,7 +26,6 @@
 
 - (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
 {
-    NSString* cbId = command.callbackId;
     NSDictionary* deviceProperties = [self deviceProperties];
     NSMutableString* result = [[NSMutableString alloc] initWithFormat:@""];
     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
@@ -49,7 +48,7 @@
         NSLog(@"%@", jsResult);
     }
 
-    [self success:pluginResult callbackId:cbId];
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
 }
 
 - (NSDictionary*)deviceProperties

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVFile.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.h b/CordovaLib/Classes/CDVFile.h
index a822c14..478ebf3 100644
--- a/CordovaLib/Classes/CDVFile.h
+++ b/CordovaLib/Classes/CDVFile.h
@@ -63,7 +63,7 @@ typedef int CDVFileSystemType;
 - (void)getMetadata:(CDVInvokedUrlCommand*)command;
 - (void)removeRecursively:(CDVInvokedUrlCommand*)command;
 - (void)remove:(CDVInvokedUrlCommand*)command;
-- (NSString*)doRemove:(NSString*)fullPath callback:(NSString*)callbackId;
+- (CDVPluginResult*)doRemove:(NSString*)fullPath;
 - (void)copyTo:(CDVInvokedUrlCommand*)command;
 - (void)moveTo:(CDVInvokedUrlCommand*)command;
 - (BOOL)canCopyMoveSrc:(NSString*)src ToDestination:(NSString*)dest;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 14cf61b..fdea0d1 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -137,7 +137,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
 - (void)requestFileSystem:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
     NSArray* arguments = command.arguments;
 
     // arguments
@@ -146,11 +145,9 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
     int type = [strType intValue];
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     if (type > 1) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:NOT_FOUND_ERR];
         NSLog(@"iOS only supports TEMPORARY and PERSISTENT file systems");
     } else {
         // NSString* fullPath = [NSString stringWithFormat:@"/%@", (type == 0 ? [self.appTempPath lastPathComponent] : [self.appDocsPath lastPathComponent])];
@@ -159,18 +156,16 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         NSNumber* pNumAvail = [self checkFreeDiskSpace:fullPath];
         // NSLog(@"Free space: %@", [NSString stringWithFormat:@"%qu", [ pNumAvail unsignedLongLongValue ]]);
         if (pNumAvail && ([pNumAvail unsignedLongLongValue] < size)) {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:QUOTA_EXCEEDED_ERR];
-            jsString = [result toErrorCallbackString:callbackId];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:QUOTA_EXCEEDED_ERR];
         } else {
             NSMutableDictionary* fileSystem = [NSMutableDictionary dictionaryWithCapacity:2];
             [fileSystem setObject:(type == TEMPORARY ? kW3FileTemporary:kW3FilePersistent) forKey:@"name"];
             NSDictionary* dirEntry = [self getDirectoryEntry:fullPath isDirectory:YES];
             [fileSystem setObject:dirEntry forKey:@"root"];
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
-            jsString = [result toSuccessCallbackString:callbackId];
         }
     }
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* Creates a dictionary representing an Entry Object
@@ -217,13 +212,9 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* inputUri = [command.arguments objectAtIndex:0];
 
-    NSString* jsString = nil;
-
     // don't know if string is encoded or not so unescape
     NSString* cleanUri = [inputUri stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     // now escape in order to create URL
@@ -233,8 +224,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
     if (!testUri || ![testUri isFileURL]) {
         // issue ENCODING_ERR
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:ENCODING_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ENCODING_ERR];
     } else {
         NSFileManager* fileMgr = [[NSFileManager alloc] init];
         NSString* path = [testUri path];
@@ -258,21 +248,18 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
             }
             if (foundFullPath == nil) {
                 // error SECURITY_ERR - not one of the two paths types supported
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:SECURITY_ERR];
-                jsString = [result toErrorCallbackString:callbackId];
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:SECURITY_ERR];
             } else {
                 NSDictionary* fileSystem = [self getDirectoryEntry:path isDirectory:isDir];
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
-                jsString = [result toSuccessCallbackString:callbackId];
             }
         } else {
             // return NOT_FOUND_ERR
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-            jsString = [result toErrorCallbackString:callbackId];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
         }
     }
-    if (jsString != nil) {
-        [self writeJavascript:jsString];
+    if (result != nil) {
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
     }
 }
 
@@ -337,14 +324,11 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)getFile:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments are URL encoded
     NSString* fullPath = [command.arguments objectAtIndex:0];
     NSString* requestedPath = [command.arguments objectAtIndex:1];
     NSDictionary* options = [command.arguments objectAtIndex:2 withDefault:nil];
 
-    NSString* jsString = nil;
     CDVPluginResult* result = nil;
     BOOL bDirRequest = NO;
     BOOL create = NO;
@@ -415,18 +399,16 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
                 // NSLog(@"newly created file/dir (%@) exists: %d", reqFullPath, [fileMgr fileExistsAtPath:reqFullPath]);
                 // file existed or was created
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self getDirectoryEntry:reqFullPath isDirectory:bDirRequest]];
-                jsString = [result toSuccessCallbackString:callbackId];
             }
         } // are all possible conditions met?
     }
 
     if (errorCode > 0) {
         // create error callback
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errorCode];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:errorCode];
     }
 
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /*
@@ -440,13 +422,10 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)getParent:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments are URL encoded
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     NSString* newPath = nil;
 
     if ([fullPath isEqualToString:self.appDocsPath] || [fullPath isEqualToString:self.appTempPath]) {
@@ -465,15 +444,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         BOOL bExists = [fileMgr fileExistsAtPath:newPath isDirectory:&bIsDir];
         if (bExists) {
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self getDirectoryEntry:newPath isDirectory:bIsDir]];
-            jsString = [result toSuccessCallbackString:callbackId];
         }
     }
-    if (!jsString) {
+    if (!result) {
         // invalid path or file does not exist
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
     }
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /*
@@ -482,8 +459,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)getMetadata:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
     NSString* testPath = argPath; // [self getFullPath: argPath];
@@ -491,7 +466,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
     NSError* __autoreleasing error = nil;
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     NSDictionary* fileAttribs = [fileMgr attributesOfItemAtPath:testPath error:&error];
 
@@ -499,7 +473,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         NSDate* modDate = [fileAttribs fileModificationDate];
         if (modDate) {
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[modDate timeIntervalSince1970] * 1000];
-            jsString = [result toSuccessCallbackString:callbackId];
         }
     } else {
         // didn't get fileAttribs
@@ -510,11 +483,12 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         }
         // log [NSNumber numberWithDouble: theMessage] objCtype to see what it returns
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errorCode];
-        jsString = [result toErrorCallbackString:callbackId];
     }
-    if (jsString) {
-        [self writeJavascript:jsString];
+    if (!result) {
+        // invalid path or file does not exist
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION];
     }
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /*
@@ -523,8 +497,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)setMetadata:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* filePath = [command.arguments objectAtIndex:0];
     NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:nil];
@@ -555,11 +527,10 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
     if (ok) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
-        [self writeJavascript:[result toSuccessCallbackString:callbackId]];
     } else {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
-        [self writeJavascript:[result toErrorCallbackString:callbackId]];
     }
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* removes the directory or file entry
@@ -573,13 +544,10 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 */
 - (void)remove:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     CDVFileError errorCode = 0;  // !! 0 not currently defined
 
     // error if try to remove top level (documents or tmp) dir
@@ -598,13 +566,12 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         }
     }
     if (errorCode > 0) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errorCode];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:errorCode];
     } else {
         // perform actual remove
-        jsString = [self doRemove:fullPath callback:callbackId];
+        result = [self doRemove:fullPath];
     }
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* recursively removes the directory
@@ -617,23 +584,18 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)removeRecursively:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     // error if try to remove top level (documents or tmp) dir
     if ([fullPath isEqualToString:self.appDocsPath] || [fullPath isEqualToString:self.appTempPath]) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
     } else {
-        jsString = [self doRemove:fullPath callback:callbackId];
+        result = [self doRemove:fullPath];
     }
-
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* remove the file or directory (recursively)
@@ -643,10 +605,9 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  * called from remove and removeRecursively - check all pubic api specific error conditions (dir not empty, etc) before calling
  */
 
-- (NSString*)doRemove:(NSString*)fullPath callback:(NSString*)callbackId
+- (CDVPluginResult*)doRemove:(NSString*)fullPath
 {
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     BOOL bSuccess = NO;
     NSError* __autoreleasing pError = nil;
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
@@ -654,8 +615,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     @try {
         bSuccess = [fileMgr removeItemAtPath:fullPath error:&pError];
         if (bSuccess) {
-            CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
-            jsString = [result toSuccessCallbackString:callbackId];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
         } else {
             // see if we can give a useful error
             CDVFileError errorCode = ABORT_ERR;
@@ -666,17 +626,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
                 errorCode = NO_MODIFICATION_ALLOWED_ERR;
             }
 
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errorCode];
-            jsString = [result toErrorCallbackString:callbackId];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:errorCode];
         }
     } @catch(NSException* e) {  // NSInvalidArgumentException if path is . or ..
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:SYNTAX_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:SYNTAX_ERR];
     }
 
-    @finally {
-        return jsString;
-    }
+    return result;
 }
 
 - (void)copyTo:(CDVInvokedUrlCommand*)command
@@ -729,17 +685,15 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)doCopyMove:(CDVInvokedUrlCommand*)command isCopy:(BOOL)bCopy
 {
-    NSString* callbackId = command.callbackId;
     NSArray* arguments = command.arguments;
 
     // arguments
     NSString* srcFullPath = [arguments objectAtIndex:0];
     NSString* destRootPath = [arguments objectAtIndex:1];
     // optional argument
-    NSString* newName = ([arguments count] > 2) ?[arguments objectAtIndex:2] :[srcFullPath lastPathComponent];          // use last component from appPath if new name not provided
+    NSString* newName = ([arguments count] > 2) ? [arguments objectAtIndex:2] : [srcFullPath lastPathComponent];          // use last component from appPath if new name not provided
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     CDVFileError errCode = 0;  // !! Currently 0 is not defined, use this to signal error !!
 
     /*NSString* destRootPath = nil;
@@ -824,7 +778,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
                     // should verify it is there and of the correct type???
                     NSDictionary* newEntry = [self getDirectoryEntry:newFullPath isDirectory:bSrcIsDir];  // should be the same type as source
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newEntry];
-                    jsString = [result toSuccessCallbackString:callbackId];
                 } else {
                     errCode = INVALID_MODIFICATION_ERR; // catch all
                     if (error) {
@@ -841,13 +794,9 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         }
     }
     if (errCode > 0) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errCode];
-        jsString = [result toErrorCallbackString:callbackId];
-    }
-
-    if (jsString) {
-        [self writeJavascript:jsString];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:errCode];
     }
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* return the URI to the entry
@@ -886,13 +835,10 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 }*/
 - (void)getFileMetadata:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     NSString* fullPath = argPath; // [self getFullPath: argPath];
 
@@ -902,8 +848,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         // make sure it exists and is not a directory
         BOOL bExists = [fileMgr fileExistsAtPath:fullPath isDirectory:&bIsDir];
         if (!bExists || bIsDir) {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-            jsString = [result toErrorCallbackString:callbackId];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
         } else {
             // create dictionary of file info
             NSError* __autoreleasing error = nil;
@@ -917,22 +862,20 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
             NSNumber* msDate = [NSNumber numberWithDouble:[modDate timeIntervalSince1970] * 1000];
             [fileInfo setObject:msDate forKey:@"lastModifiedDate"];
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileInfo];
-            jsString = [result toSuccessCallbackString:callbackId];
         }
     }
-
-    [self writeJavascript:jsString];
+    if (!result) {
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_INSTANTIATION_EXCEPTION];
+    }
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 - (void)readEntries:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
     NSError* __autoreleasing error = nil;
@@ -952,14 +895,12 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
             }
         }
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:entries];
-        jsString = [result toSuccessCallbackString:callbackId];
     } else {
         // assume not found but could check error for more specific error conditions
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
     }
 
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 // DEPRECATED
@@ -977,20 +918,16 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  */
 - (void)readAsText:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
     // NSString* encoding = [command.arguments objectAtIndex:2];   // not currently used
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     NSFileHandle* file = [NSFileHandle fileHandleForReadingAtPath:argPath];
 
     if (!file) {
         // invalid path entry
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:NOT_FOUND_ERR];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
     } else {
         NSData* readData = [file readDataToEndOfFile];
 
@@ -1004,11 +941,8 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         }
 
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[pNStrBuff stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-        jsString = [result toSuccessCallbackString:callbackId];
-    }
-    if (jsString) {
-        [self writeJavascript:jsString];
     }
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* Read content of text file and return as base64 encoded data url.
@@ -1021,14 +955,11 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
 - (void)readAsDataURL:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
 
     CDVFileError errCode = ABORT_ERR;
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
 
     if (!argPath) {
         errCode = SYNTAX_ERR;
@@ -1044,18 +975,16 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
             if (readData) {
                 NSString* output = [NSString stringWithFormat:@"data:%@;base64,%@", mimeType, [readData base64EncodedString]];
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:output];
-                jsString = [result toSuccessCallbackString:callbackId];
             } else {
                 errCode = NOT_FOUND_ERR;
             }
         }
     }
-    if (!jsString) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errCode];
-        jsString = [result toErrorCallbackString:callbackId];
+    if (!result) {
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errCode];
     }
     // NSLog(@"readAsDataURL return: %@", jsString);
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 /* helper function to get the mimeType from the file extension
@@ -1095,8 +1024,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
 - (void)truncate:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
     unsigned long long pos = (unsigned long long)[[command.arguments objectAtIndex:1] longLongValue];
@@ -1106,7 +1033,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     unsigned long long newPos = [self truncateFile:appFile atPosition:pos];
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:newPos];
 
-    [self writeJavascript:[result toSuccessCallbackString:callbackId]];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 - (unsigned long long)truncateFile:(NSString*)filePath atPosition:(unsigned long long)pos
@@ -1151,7 +1078,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 - (void)writeToFile:(NSString*)filePath withData:(NSString*)data append:(BOOL)shouldAppend callback:(NSString*)callbackId
 {
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     CDVFileError errCode = INVALID_MODIFICATION_ERR;
     int bytesWritten = 0;
     NSData* encData = [data dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
@@ -1167,7 +1093,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
             [fileStream close];
             if (bytesWritten > 0) {
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:bytesWritten];
-                jsString = [result toSuccessCallbackString:callbackId];
                 // } else {
                 // can probably get more detailed error info via [fileStream streamError]
                 // errCode already set to INVALID_MODIFICATION_ERR;
@@ -1178,22 +1103,18 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         // invalid filePath
         errCode = NOT_FOUND_ERR;
     }
-    if (!jsString) {
+    if (!result) {
         // was an error
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:errCode];
-        jsString = [result toErrorCallbackString:callbackId];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errCode];
     }
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
 - (void)testFileExists:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
 
-    NSString* jsString = nil;
     // Get the file manager
     NSFileManager* fMgr = [NSFileManager defaultManager];
     NSString* appFile = argPath; // [ self getFullPath: argPath];
@@ -1201,20 +1122,14 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     BOOL bExists = [fMgr fileExistsAtPath:appFile];
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(bExists ? 1:0)];
 
-    // keep original format of returning 0 or 1 to success  callback
-    jsString = [result toSuccessCallbackString:callbackId];
-
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 - (void)testDirectoryExists:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
 
-    NSString* jsString = nil;
     // Get the file manager
     NSFileManager* fMgr = [[NSFileManager alloc] init];
     NSString* appFile = argPath; // [self getFullPath: argPath];
@@ -1223,16 +1138,12 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:((bExists && bIsDir) ? 1:0)];
 
-    // keep original format of returning 0 or 1 to success callback
-    jsString = [result toSuccessCallbackString:callbackId];
-    [self writeJavascript:jsString];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 // Returns number of bytes available via callback
 - (void)getFreeDiskSpace:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     // no arguments
 
     NSNumber* pNumAvail = [self checkFreeDiskSpace:self.appDocsPath];
@@ -1242,7 +1153,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:strFreeSpace];
 
-    [self writeJavascript:[result toSuccessCallbackString:callbackId]];
+    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
 }
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 04f4e93..c2139fb 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -156,9 +156,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     }
 
     if (errorCode > 0) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self createFileTransferError:errorCode AndSource:target AndTarget:server]];
-
-        [self writeJavascript:[result toErrorCallbackString:command.callbackId]];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[self createFileTransferError:errorCode AndSource:target AndTarget:server]];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
         return nil;
     }
 
@@ -264,7 +263,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     NSString* target = (NSString*)[command.arguments objectAtIndex:0];
     NSError* __autoreleasing err = nil;
     // Extract the path part out of a file: URL.
-    NSString* filePath = [target hasPrefix:@"/"] ?[target copy] :[[NSURL URLWithString:target] path];
+    NSString* filePath = [target hasPrefix:@"/"] ? [target copy] : [[NSURL URLWithString:target] path];
 
     // Memory map the file so that it can be read efficiently even if it is large.
     NSData* fileData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&err];
@@ -304,9 +303,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
         [delegate.connection cancel];
         [activeTransfers removeObjectForKey:objectId];
 
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self createFileTransferError:CONNECTION_ABORTED AndSource:delegate.source AndTarget:delegate.target]];
-
-        [self writeJavascript:[result toErrorCallbackString:delegate.callbackId]];
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[self createFileTransferError:CONNECTION_ABORTED AndSource:delegate.source AndTarget:delegate.target]];
+        [self.commandDelegate sendPluginResult:result callbackId:delegate.callbackId];
     }
 }
 
@@ -339,9 +337,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     }
 
     if (errorCode > 0) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self createFileTransferError:errorCode AndSource:sourceUrl AndTarget:filePath]];
-
-        [self writeJavascript:[result toErrorCallbackString:command.callbackId]];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[self createFileTransferError:errorCode AndSource:sourceUrl AndTarget:filePath]];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
         return;
     }
 
@@ -413,11 +410,10 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     NSString* uploadResponse = nil;
     BOOL downloadResponse;
     NSMutableDictionary* uploadResult;
-    CDVPluginResult* result;
+    CDVPluginResult* result = nil;
     NSError* __autoreleasing error = nil;
     NSString* parentPath;
     BOOL bDirRequest = NO;
-    BOOL errored = NO;
     CDVFile* file;
 
     NSLog(@"File Transfer Finished with response code %d", self.responseCode);
@@ -434,8 +430,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
             [uploadResult setObject:[NSNumber numberWithInt:self.responseCode] forKey:@"responseCode"];
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:uploadResult];
         } else {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
-            errored = YES;
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
         }
     }
     if (self.direction == CDV_TRANSFER_DOWNLOAD) {
@@ -455,8 +450,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
 
                 if (downloadResponse == NO) {
                     // send our results back
-                    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[command createFileTransferError:INVALID_URL_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
-                    errored = YES;
+                    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command createFileTransferError:INVALID_URL_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
                 } else {
                     DLog(@"File Transfer Download success");
 
@@ -467,20 +461,14 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
             }
             @catch(id exception) {
                 // jump back to main thread
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[command createFileTransferError:FILE_NOT_FOUND_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
-                errored = YES;
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsDictionary:[command createFileTransferError:FILE_NOT_FOUND_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
             }
         } else {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
-            errored = YES;
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
         }
     }
 
-    if (!errored) {
-        [self.command writeJavascript:[result toSuccessCallbackString:callbackId]];
-    } else {
-        [self.command writeJavascript:[result toErrorCallbackString:callbackId]];
-    }
+    [self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
 
     // remove connection for activeTransfers
     [command.activeTransfers removeObjectForKey:objectId];
@@ -496,14 +484,13 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
 
 - (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
 {
-    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
+    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command createFileTransferError:CONNECTION_ERR AndSource:source AndTarget:target AndHttpStatus:self.responseCode]];
 
     NSLog(@"File Transfer Error: %@", [error localizedDescription]);
 
     // remove connection for activeTransfers
     [command.activeTransfers removeObjectForKey:objectId];
-
-    [self.command writeJavascript:[result toErrorCallbackString:callbackId]];
+    [self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
 - (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
@@ -519,7 +506,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
         [downloadProgress setObject:[NSNumber numberWithInt:self.bytesExpected] forKey:@"total"];
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:downloadProgress];
         [result setKeepCallbackAsBool:true];
-        [self.command writeJavascript:[result toSuccessCallbackString:callbackId]];
+        [self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -533,7 +520,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
         [uploadProgress setObject:[NSNumber numberWithInt:totalBytesExpectedToWrite] forKey:@"total"];
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:uploadProgress];
         [result setKeepCallbackAsBool:true];
-        [self.command writeJavascript:[result toSuccessCallbackString:callbackId]];
+        [self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
     self.bytesTransfered = totalBytesWritten;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVLocalStorage.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocalStorage.m b/CordovaLib/Classes/CDVLocalStorage.m
index 51a3f1a..0e539f1 100644
--- a/CordovaLib/Classes/CDVLocalStorage.m
+++ b/CordovaLib/Classes/CDVLocalStorage.m
@@ -212,13 +212,13 @@
                     NSLog(@"%@", message);
 
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
-                    [self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:callbackId] waitUntilDone:NO];
+                    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
                 } else {
                     message = [NSString stringWithFormat:@"Error in CDVLocalStorage (%@) backup: %@", info.label, [error localizedDescription]];
                     NSLog(@"%@", message);
 
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:message];
-                    [self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toErrorCallbackString:callbackId] waitUntilDone:NO];
+                    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
                 }
             }
         }
@@ -228,8 +228,6 @@
 /* copy from persistentDbLocation to webkitDbLocation */
 - (void)restore:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-
     NSError* __autoreleasing error = nil;
     CDVPluginResult* result = nil;
     NSString* message = nil;
@@ -243,13 +241,13 @@
                 NSLog(@"%@", message);
 
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
-                [self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:callbackId] waitUntilDone:NO];
+                [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
             } else {
                 message = [NSString stringWithFormat:@"Error in CDVLocalStorage (%@) restore: %@", info.label, [error localizedDescription]];
                 NSLog(@"%@", message);
 
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:message];
-                [self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toErrorCallbackString:callbackId] waitUntilDone:NO];
+                [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVLocation.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocation.m b/CordovaLib/Classes/CDVLocation.m
index 9d2dd60..9814f35 100644
--- a/CordovaLib/Classes/CDVLocation.m
+++ b/CordovaLib/Classes/CDVLocation.m
@@ -241,7 +241,7 @@
         [posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
         [posError setObject:@"Location services are disabled." forKey:@"message"];
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         if (!self.locationData) {
             self.locationData = [[CDVLocationData alloc] init];
@@ -287,7 +287,7 @@
         [posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
         [posError setObject:@"Location services are disabled." forKey:@"message"];
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         if (!__locationStarted || (__highAccuracyEnabled != enableHighAccuracy)) {
             // Tell the location manager to start notifying us of location updates
@@ -313,13 +313,11 @@
 - (void)returnLocationInfo:(NSString*)callbackId andKeepCallback:(BOOL)keepCallback
 {
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     CDVLocationData* lData = self.locationData;
 
     if (lData && !lData.locationInfo) {
         // return error
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:POSITIONUNAVAILABLE];
-        jsString = [result toErrorCallbackString:callbackId];
     } else if (lData && lData.locationInfo) {
         CLLocation* lInfo = lData.locationInfo;
         NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:8];
@@ -335,11 +333,9 @@
 
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
         [result setKeepCallbackAsBool:keepCallback];
-
-        jsString = [result toSuccessCallbackString:callbackId];
     }
-    if (jsString) {
-        [super writeJavascript:jsString];
+    if (result) {
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -352,13 +348,13 @@
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
 
     for (NSString* callbackId in self.locationData.locationCallbacks) {
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 
     [self.locationData.locationCallbacks removeAllObjects];
 
     for (NSString* callbackId in self.locationData.watchCallbacks) {
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -377,7 +373,7 @@
     }
     if ([self hasHeadingSupport] == NO) {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:20];
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         // heading retrieval does is not affected by disabling locationServices and authorization of app for location services
         if (!self.headingData) {
@@ -410,7 +406,7 @@
 
     if ([self hasHeadingSupport] == NO) {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:20];
-        [super writeJavascript:[result toErrorCallbackString:callbackId]];
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     } else {
         if (!hData) {
             self.headingData = [[CDVHeadingData alloc] init];
@@ -437,7 +433,6 @@
 - (void)returnHeadingInfo:(NSString*)callbackId keepCallback:(BOOL)bRetain
 {
     CDVPluginResult* result = nil;
-    NSString* jsString = nil;
     CDVHeadingData* hData = self.headingData;
 
     self.headingData.headingTimestamp = [NSDate date];
@@ -445,7 +440,6 @@
     if (hData && (hData.headingStatus == HEADINGERROR)) {
         // return error
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:0];
-        jsString = [result toErrorCallbackString:callbackId];
     } else if (hData && (hData.headingStatus == HEADINGRUNNING) && hData.headingInfo) {
         // if there is heading info, return it
         CLHeading* hInfo = hData.headingInfo;
@@ -459,11 +453,9 @@
 
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
         [result setKeepCallbackAsBool:bRetain];
-
-        jsString = [result toSuccessCallbackString:callbackId];
     }
-    if (jsString) {
-        [super writeJavascript:jsString];
+    if (result) {
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
     }
 }
 
@@ -555,14 +547,14 @@
                 // heading error during startup - report error
                 for (NSString* callbackId in hData.headingCallbacks) {
                     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:0];
-                    [super writeJavascript:[result toErrorCallbackString:callbackId]];
+                    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
                 }
 
                 [hData.headingCallbacks removeAllObjects];
             } // else for frequency watches next call to getCurrentHeading will report error
             if (hData.headingFilter) {
                 CDVPluginResult* resultFilter = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:0];
-                [super writeJavascript:[resultFilter toErrorCallbackString:hData.headingFilter]];
+                [self.commandDelegate sendPluginResult:resultFilter callbackId:hData.headingFilter];
             }
             hData.headingStatus = HEADINGERROR;
         }
@@ -599,7 +591,6 @@
     self.headingData = nil;
 }
 
-
 @end
 
 #pragma mark -
@@ -612,7 +603,7 @@
     return [NSString stringWithFormat:
         @"{ timestamp: %.00f, \
             coords: { latitude: %f, longitude: %f, altitude: %.02f, heading: %.02f, speed: %.02f, accuracy: %.02f, altitudeAccuracy: %.02f } \
-            }"                                                                                                                                                                               ,
+            }",
         [self.timestamp timeIntervalSince1970] * 1000.0,
         self.coordinate.latitude,
         self.coordinate.longitude,

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/035e2fb9/CordovaLib/Classes/CDVNotification.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVNotification.m b/CordovaLib/Classes/CDVNotification.m
index 3feafb1..992239e 100644
--- a/CordovaLib/Classes/CDVNotification.m
+++ b/CordovaLib/Classes/CDVNotification.m
@@ -49,9 +49,9 @@
     NSArray* arguments = command.arguments;
     int argc = [arguments count];
 
-    NSString* message = argc > 0 ?[arguments objectAtIndex:0] : nil;
-    NSString* title = argc > 1 ?[arguments objectAtIndex:1] : nil;
-    NSString* buttons = argc > 2 ?[arguments objectAtIndex:2] : nil;
+    NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
+    NSString* title = argc > 1 ? [arguments objectAtIndex:1] : nil;
+    NSString* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
 
     if (!title) {
         title = NSLocalizedString(@"Alert", @"Alert");
@@ -69,9 +69,9 @@
     NSArray* arguments = command.arguments;
     int argc = [arguments count];
 
-    NSString* message = argc > 0 ?[arguments objectAtIndex:0] : nil;
-    NSString* title = argc > 1 ?[arguments objectAtIndex:1] : nil;
-    NSString* buttons = argc > 2 ?[arguments objectAtIndex:2] : nil;
+    NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
+    NSString* title = argc > 1 ? [arguments objectAtIndex:1] : nil;
+    NSString* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
 
     if (!title) {
         title = NSLocalizedString(@"Confirm", @"Confirm");
@@ -92,7 +92,7 @@
     CDVAlertView* cdvAlertView = (CDVAlertView*)alertView;
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:++buttonIndex];
 
-    [self writeJavascript:[result toSuccessCallbackString:cdvAlertView.callbackId]];
+    [self.commandDelegate sendPluginResult:result callbackId:cdvAlertView.callbackId];
 }
 
 - (void)vibrate:(CDVInvokedUrlCommand*)command


Mime
View raw message