Browse Source

#1 correct ios progress report value

Ben Hsieh 8 years ago
parent
commit
d0455c987c
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      src/ios/RNFetchBlob/RNFetchBlob.m

+ 4
- 2
src/ios/RNFetchBlob/RNFetchBlob.m View File

54
     self.respData = [[NSMutableData alloc] initWithLength:0];
54
     self.respData = [[NSMutableData alloc] initWithLength:0];
55
     self.callback = callback;
55
     self.callback = callback;
56
     self.bridge = bridgeRef;
56
     self.bridge = bridgeRef;
57
+    self.expectedBytes = 0;
58
+    self.receivedBytes = 0;
57
     // Call long-running code on background thread
59
     // Call long-running code on background thread
58
     NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:NO];
60
     NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:NO];
59
     [conn scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
61
     [conn scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
74
 }
76
 }
75
 
77
 
76
 - (void) connection:(NSURLConnection *)connection didReceiveData:(nonnull NSData *)data {
78
 - (void) connection:(NSURLConnection *)connection didReceiveData:(nonnull NSData *)data {
77
-    receivedBytes = data.length;
79
+    receivedBytes += data.length;
78
     [respData appendData:data];
80
     [respData appendData:data];
79
     
81
     
80
     [self.bridge.eventDispatcher
82
     [self.bridge.eventDispatcher
90
 - (void) connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
92
 - (void) connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
91
     
93
     
92
     expectedBytes = totalBytesExpectedToWrite;
94
     expectedBytes = totalBytesExpectedToWrite;
93
-    receivedBytes = totalBytesWritten;
95
+    receivedBytes += totalBytesWritten;
94
     [self.bridge.eventDispatcher
96
     [self.bridge.eventDispatcher
95
         sendAppEventWithName:@"RNFetchBlobProgress"
97
         sendAppEventWithName:@"RNFetchBlobProgress"
96
             body:@{
98
             body:@{