|
@@ -70,18 +70,17 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
70
|
70
|
|
71
|
71
|
@interface RNFetchBlobNetwork ()
|
72
|
72
|
{
|
73
|
|
- BOOL * respFile;
|
|
73
|
+ BOOL respFile;
|
74
|
74
|
BOOL isNewPart;
|
75
|
|
- BOOL * isIncrement;
|
|
75
|
+ BOOL isIncrement;
|
76
|
76
|
NSMutableData * partBuffer;
|
77
|
77
|
NSString * destPath;
|
78
|
78
|
NSOutputStream * writeStream;
|
79
|
79
|
long bodyLength;
|
80
|
|
- NSMutableDictionary * respInfo;
|
81
|
80
|
NSInteger respStatus;
|
82
|
81
|
NSMutableArray * redirects;
|
83
|
82
|
ResponseFormat responseFormat;
|
84
|
|
- BOOL * followRedirect;
|
|
83
|
+ BOOL followRedirect;
|
85
|
84
|
BOOL backgroundTask;
|
86
|
85
|
}
|
87
|
86
|
|
|
@@ -97,8 +96,6 @@ NSOperationQueue *taskQueue;
|
97
|
96
|
@synthesize callback;
|
98
|
97
|
@synthesize bridge;
|
99
|
98
|
@synthesize options;
|
100
|
|
-@synthesize fileTaskCompletionHandler;
|
101
|
|
-@synthesize dataTaskCompletionHandler;
|
102
|
99
|
@synthesize error;
|
103
|
100
|
|
104
|
101
|
|
|
@@ -121,7 +118,7 @@ NSOperationQueue *taskQueue;
|
121
|
118
|
{
|
122
|
119
|
progressTable = [[NSMutableDictionary alloc] init];
|
123
|
120
|
}
|
124
|
|
- [progressTable setValue:config forKey:taskId];
|
|
121
|
+ if (config) [progressTable setValue:config forKey:taskId];
|
125
|
122
|
}
|
126
|
123
|
}
|
127
|
124
|
|
|
@@ -132,7 +129,7 @@ NSOperationQueue *taskQueue;
|
132
|
129
|
{
|
133
|
130
|
uploadProgressTable = [[NSMutableDictionary alloc] init];
|
134
|
131
|
}
|
135
|
|
- [uploadProgressTable setValue:config forKey:taskId];
|
|
132
|
+ if (config) [uploadProgressTable setValue:config forKey:taskId];
|
136
|
133
|
}
|
137
|
134
|
}
|
138
|
135
|
|
|
@@ -193,9 +190,8 @@ NSOperationQueue *taskQueue;
|
193
|
190
|
responseFormat = AUTO;
|
194
|
191
|
|
195
|
192
|
NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
|
196
|
|
- NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
|
197
|
193
|
NSString * key = [self.options valueForKey:CONFIG_KEY];
|
198
|
|
- __block NSURLSession * session;
|
|
194
|
+ NSURLSession * session;
|
199
|
195
|
|
200
|
196
|
bodyLength = contentLength;
|
201
|
197
|
|
|
@@ -246,16 +242,15 @@ NSOperationQueue *taskQueue;
|
246
|
242
|
respFile = NO;
|
247
|
243
|
}
|
248
|
244
|
|
249
|
|
- __block NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
|
|
245
|
+ NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
|
250
|
246
|
@synchronized ([RNFetchBlobNetwork class]){
|
251
|
247
|
[taskTable setObject:task forKey:taskId];
|
252
|
|
- [task resume];
|
253
|
248
|
}
|
|
249
|
+ [task resume];
|
254
|
250
|
|
255
|
251
|
// network status indicator
|
256
|
252
|
if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
|
257
|
253
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
|
258
|
|
- __block UIApplication * app = [UIApplication sharedApplication];
|
259
|
254
|
|
260
|
255
|
}
|
261
|
256
|
|
|
@@ -269,7 +264,7 @@ NSOperationQueue *taskQueue;
|
269
|
264
|
while((key = [emu nextObject]))
|
270
|
265
|
{
|
271
|
266
|
RCTBridge * bridge = [RNFetchBlob getRCTBridge];
|
272
|
|
- NSData * args = @{ @"taskId": key };
|
|
267
|
+ id args = @{ @"taskId": key };
|
273
|
268
|
[bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
|
274
|
269
|
|
275
|
270
|
}
|
|
@@ -352,23 +347,14 @@ NSOperationQueue *taskQueue;
|
352
|
347
|
{
|
353
|
348
|
respType = @"blob";
|
354
|
349
|
// for XMLHttpRequest, switch response data handling strategy automatically
|
355
|
|
- if([options valueForKey:@"auto"] == YES) {
|
|
350
|
+ if([options valueForKey:@"auto"]) {
|
356
|
351
|
respFile = YES;
|
357
|
352
|
destPath = [RNFetchBlobFS getTempPath:taskId withExtension:@""];
|
358
|
353
|
}
|
359
|
354
|
}
|
360
|
|
- }
|
361
|
|
- else
|
|
355
|
+ } else {
|
362
|
356
|
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
|
+ }
|
372
|
358
|
|
373
|
359
|
#pragma mark - handling cookies
|
374
|
360
|
// # 153 get cookies
|
|
@@ -383,11 +369,16 @@ NSOperationQueue *taskQueue;
|
383
|
369
|
|
384
|
370
|
[self.bridge.eventDispatcher
|
385
|
371
|
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
|
+ }
|
387
|
381
|
];
|
388
|
|
- headers = nil;
|
389
|
|
- respInfo = nil;
|
390
|
|
-
|
391
|
382
|
}
|
392
|
383
|
else
|
393
|
384
|
NSLog(@"oops");
|
|
@@ -475,8 +466,8 @@ NSOperationQueue *taskQueue;
|
475
|
466
|
sendDeviceEventWithName:EVENT_PROGRESS
|
476
|
467
|
body:@{
|
477
|
468
|
@"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],
|
480
|
471
|
@"chunk": chunkString
|
481
|
472
|
}
|
482
|
473
|
];
|
|
@@ -494,17 +485,12 @@ NSOperationQueue *taskQueue;
|
494
|
485
|
{
|
495
|
486
|
|
496
|
487
|
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;
|
500
|
491
|
|
501
|
492
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
|
502
|
493
|
|
503
|
|
- if(respInfo == nil)
|
504
|
|
- {
|
505
|
|
- respInfo = [NSNull null];
|
506
|
|
- }
|
507
|
|
-
|
508
|
494
|
if(error != nil)
|
509
|
495
|
{
|
510
|
496
|
errMsg = [error localizedDescription];
|
|
@@ -550,7 +536,11 @@ NSOperationQueue *taskQueue;
|
550
|
536
|
}
|
551
|
537
|
|
552
|
538
|
|
553
|
|
- callback(@[ errMsg, rnfbRespType, respStr]);
|
|
539
|
+ callback(@[
|
|
540
|
+ errMsg ?: [NSNull null],
|
|
541
|
+ rnfbRespType ?: @"",
|
|
542
|
+ respStr ?: [NSNull null]
|
|
543
|
+ ]);
|
554
|
544
|
|
555
|
545
|
@synchronized ([RNFetchBlobNetwork class])
|
556
|
546
|
{
|
|
@@ -608,7 +598,7 @@ NSOperationQueue *taskQueue;
|
608
|
598
|
|
609
|
599
|
- (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable credantial))completionHandler
|
610
|
600
|
{
|
611
|
|
- BOOL trusty = [options valueForKey:CONFIG_TRUSTY];
|
|
601
|
+ BOOL trusty = [[options valueForKey:CONFIG_TRUSTY] boolValue];
|
612
|
602
|
if(!trusty)
|
613
|
603
|
{
|
614
|
604
|
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
|