Updated Branches:
  refs/heads/master d0488e3be -> fd72ae269

Fix bug in FileTransfer progress events.

Use only download progress for .download(), and only upload progress for
.upload()


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/fd72ae26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/fd72ae26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/fd72ae26

Branch: refs/heads/master
Commit: fd72ae2690f5f7d2ebdf82aa8512416d5c4e901c
Parents: d0488e3
Author: Andrew Grieve <agri...@chromium.org>
Authored: Mon Sep 24 14:04:24 2012 -0400
Committer: Andrew Grieve <agri...@chromium.org>
Committed: Mon Sep 24 14:04:24 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFileTransfer.m |   36 +++++++++++++++-------------
 1 files changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/fd72ae26/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m 
b/CordovaLib/Classes/CDVFileTransfer.m
index d37702b..eaaa3ca 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -502,28 +502,30 @@ static CFIndex WriteDataToStream(NSData* data, 
CFWriteStreamRef stream)
     self.bytesTransfered += data.length;
     [self.responseData appendData:data];
 
-    BOOL lengthComputable = (self.bytesExpected != NSURLResponseUnknownLength);
-    NSMutableDictionary* downloadProgress = [NSMutableDictionary 
dictionaryWithCapacity:3];
-    [downloadProgress setObject:[NSNumber numberWithBool:lengthComputable] 
forKey:@"lengthComputable"];
-    [downloadProgress setObject:[NSNumber numberWithInt:self.bytesTransfered] 
forKey:@"loaded"];
-    [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]];
+    if (self.direction == CDV_TRANSFER_DOWNLOAD) {
+        BOOL lengthComputable = (self.bytesExpected != 
NSURLResponseUnknownLength);
+        NSMutableDictionary* downloadProgress = [NSMutableDictionary 
dictionaryWithCapacity:3];
+        [downloadProgress setObject:[NSNumber numberWithBool:lengthComputable] 
forKey:@"lengthComputable"];
+        [downloadProgress setObject:[NSNumber 
numberWithInt:self.bytesTransfered] forKey:@"loaded"];
+        [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]];
+    }
 }
 
 - (void)connection:(NSURLConnection*)connection 
didSendBodyData:(NSInteger)bytesWritten 
totalBytesWritten:(NSInteger)totalBytesWritten 
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
 {
-    NSMutableDictionary* uploadProgress = [NSMutableDictionary 
dictionaryWithCapacity:3];
-
-    [uploadProgress setObject:[NSNumber numberWithBool:true] 
forKey:@"lengthComputable"];
-    [uploadProgress setObject:[NSNumber numberWithInt:totalBytesWritten] 
forKey:@"loaded"];
-    [uploadProgress setObject:[NSNumber 
numberWithInt:totalBytesExpectedToWrite] forKey:@"total"];
-    CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_OK messageAsDictionary:uploadProgress];
-    [result setKeepCallbackAsBool:true];
-    [self.command writeJavascript:[result toSuccessCallbackString:callbackId]];
+    if (self.direction == CDV_TRANSFER_UPLOAD) {
+        NSMutableDictionary* uploadProgress = [NSMutableDictionary 
dictionaryWithCapacity:3];
 
+        [uploadProgress setObject:[NSNumber numberWithBool:true] 
forKey:@"lengthComputable"];
+        [uploadProgress setObject:[NSNumber numberWithInt:totalBytesWritten] 
forKey:@"loaded"];
+        [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.bytesTransfered = totalBytesWritten;
 }
 

Reply via email to