Browse Source

Change IOS run loop strategy for better performance, related to #48

Ben Hsieh 8 years ago
parent
commit
bd92225e36
1 changed files with 10 additions and 14 deletions
  1. 10
    14
      src/ios/RNFetchBlobNetwork.m

+ 10
- 14
src/ios/RNFetchBlobNetwork.m View File

92
     
92
     
93
     // the session trust any SSL certification
93
     // the session trust any SSL certification
94
 
94
 
95
-    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
95
+    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
96
     session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
96
     session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
97
     
97
     
98
     if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
98
     if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
168
             }
168
             }
169
      ];
169
      ];
170
     
170
     
171
-    if(receivedBytes >= expectedBytes)
172
-    {
173
-        if(respFile == YES)
174
-        {
175
-            [writeStream close];
176
-            callback(@[[NSNull null], destPath]);
177
-        }
178
-        // base64 response
179
-        else {
180
-            callback(@[[NSNull null], [respData base64EncodedStringWithOptions:0]]);
181
-        }
182
-        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
183
-    }
184
 }
171
 }
185
 
172
 
186
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
173
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
187
     NSLog([error localizedDescription]);
174
     NSLog([error localizedDescription]);
188
     self.error = error;
175
     self.error = error;
189
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
176
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
177
+    if(respFile == YES)
178
+    {
179
+        [writeStream close];
180
+        callback(@[error == nil ? [NSNull null] : [error localizedDescription], destPath]);
181
+    }
182
+    // base64 response
183
+    else {
184
+        callback(@[error == nil ? [NSNull null] : [error localizedDescription], [respData base64EncodedStringWithOptions:0]]);
185
+    }
190
 }
186
 }
191
 
187
 
192
 // upload progress handler
188
 // upload progress handler