@@ -70,18 +70,17 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
7070
7171@interface RNFetchBlobNetwork ()
7272{
73- BOOL * respFile;
73+ BOOL respFile;
7474 BOOL isNewPart;
75- BOOL * isIncrement;
75+ BOOL isIncrement;
7676 NSMutableData * partBuffer;
7777 NSString * destPath;
7878 NSOutputStream * writeStream;
7979 long bodyLength;
80- NSMutableDictionary * respInfo;
8180 NSInteger respStatus;
8281 NSMutableArray * redirects;
8382 ResponseFormat responseFormat;
84- BOOL * followRedirect;
83+ BOOL followRedirect;
8584 BOOL backgroundTask;
8685}
8786
@@ -97,8 +96,6 @@ @implementation RNFetchBlobNetwork
9796@synthesize callback;
9897@synthesize bridge;
9998@synthesize options;
100- @synthesize fileTaskCompletionHandler;
101- @synthesize dataTaskCompletionHandler;
10299@synthesize error;
103100
104101
@@ -121,7 +118,7 @@ + (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)
121118 {
122119 progressTable = [[NSMutableDictionary alloc ] init ];
123120 }
124- [progressTable setValue: config forKey: taskId];
121+ if (config) [progressTable setValue: config forKey: taskId];
125122 }
126123}
127124
@@ -132,7 +129,7 @@ + (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)
132129 {
133130 uploadProgressTable = [[NSMutableDictionary alloc ] init ];
134131 }
135- [uploadProgressTable setValue: config forKey: taskId];
132+ if (config) [uploadProgressTable setValue: config forKey: taskId];
136133 }
137134}
138135
@@ -193,9 +190,8 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
193190 responseFormat = AUTO;
194191
195192 NSString * path = [self .options valueForKey: CONFIG_FILE_PATH];
196- NSString * ext = [self .options valueForKey: CONFIG_FILE_EXT];
197193 NSString * key = [self .options valueForKey: CONFIG_KEY];
198- __block NSURLSession * session;
194+ NSURLSession * session;
199195
200196 bodyLength = contentLength;
201197
@@ -246,16 +242,15 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
246242 respFile = NO ;
247243 }
248244
249- __block NSURLSessionDataTask * task = [session dataTaskWithRequest: req];
245+ NSURLSessionDataTask * task = [session dataTaskWithRequest: req];
250246 @synchronized ([RNFetchBlobNetwork class ]){
251247 [taskTable setObject: task forKey: taskId];
252- [task resume ];
253248 }
249+ [task resume ];
254250
255251 // network status indicator
256252 if ([[options objectForKey: CONFIG_INDICATOR] boolValue ] == YES )
257253 [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: YES ];
258- __block UIApplication * app = [UIApplication sharedApplication ];
259254
260255}
261256
@@ -269,7 +264,7 @@ + (void) emitExpiredTasks
269264 while ((key = [emu nextObject ]))
270265 {
271266 RCTBridge * bridge = [RNFetchBlob getRCTBridge ];
272- NSData * args = @{ @" taskId" : key };
267+ id args = @{ @" taskId" : key };
273268 [bridge.eventDispatcher sendDeviceEventWithName: EVENT_EXPIRE body: args];
274269
275270 }
@@ -352,23 +347,14 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
352347 {
353348 respType = @" blob" ;
354349 // for XMLHttpRequest, switch response data handling strategy automatically
355- if ([options valueForKey: @" auto" ] == YES ) {
350+ if ([options valueForKey: @" auto" ]) {
356351 respFile = YES ;
357352 destPath = [RNFetchBlobFS getTempPath: taskId withExtension: @" " ];
358353 }
359354 }
360- }
361- else
355+ } else {
362356 respType = @" text" ;
363- respInfo = @{
364- @" taskId" : taskId,
365- @" state" : @" 2" ,
366- @" headers" : headers,
367- @" redirects" : redirects,
368- @" respType" : respType,
369- @" timeout" : @NO ,
370- @" status" : [NSNumber numberWithInteger: statusCode]
371- };
357+ }
372358
373359#pragma mark - handling cookies
374360 // # 153 get cookies
@@ -383,11 +369,16 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
383369
384370 [self .bridge.eventDispatcher
385371 sendDeviceEventWithName: EVENT_STATE_CHANGE
386- body: respInfo
372+ body: @{
373+ @" taskId" : taskId,
374+ @" state" : @" 2" ,
375+ @" headers" : headers,
376+ @" redirects" : redirects,
377+ @" respType" : respType,
378+ @" timeout" : @NO ,
379+ @" status" : [NSNumber numberWithInteger: statusCode]
380+ }
387381 ];
388- headers = nil ;
389- respInfo = nil ;
390-
391382 }
392383 else
393384 NSLog (@" oops" );
@@ -475,8 +466,8 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
475466 sendDeviceEventWithName: EVENT_PROGRESS
476467 body: @{
477468 @" taskId" : taskId,
478- @" written" : [NSString stringWithFormat: @" %d " , receivedBytes],
479- @" total" : [NSString stringWithFormat: @" %d " , expectedBytes],
469+ @" written" : [NSString stringWithFormat: @" %ld " , ( long ) receivedBytes],
470+ @" total" : [NSString stringWithFormat: @" %ld " , ( long ) expectedBytes],
480471 @" chunk" : chunkString
481472 }
482473 ];
@@ -494,17 +485,12 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
494485{
495486
496487 self.error = error;
497- NSString * errMsg = [ NSNull null ] ;
498- NSString * respStr = [ NSNull null ] ;
499- NSString * rnfbRespType = @" " ;
488+ NSString * errMsg;
489+ NSString * respStr;
490+ NSString * rnfbRespType;
500491
501492 [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: NO ];
502493
503- if (respInfo == nil )
504- {
505- respInfo = [NSNull null ];
506- }
507-
508494 if (error != nil )
509495 {
510496 errMsg = [error localizedDescription ];
@@ -550,7 +536,11 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
550536 }
551537
552538
553- callback (@[ errMsg, rnfbRespType, respStr]);
539+ callback (@[
540+ errMsg ?: [NSNull null ],
541+ rnfbRespType ?: @" " ,
542+ respStr ?: [NSNull null ]
543+ ]);
554544
555545 @synchronized ([RNFetchBlobNetwork class ])
556546 {
@@ -608,7 +598,7 @@ + (void) cancelRequest:(NSString *)taskId
608598
609599- (void ) URLSession : (NSURLSession *)session didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition , NSURLCredential * _Nullable credantial))completionHandler
610600{
611- BOOL trusty = [options valueForKey: CONFIG_TRUSTY];
601+ BOOL trusty = [[ options valueForKey: CONFIG_TRUSTY] boolValue ];
612602 if (!trusty)
613603 {
614604 completionHandler (NSURLSessionAuthChallengePerformDefaultHandling , [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
0 commit comments