Sin descripción

RNFetchBlobNetwork.m 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. //
  2. // RNFetchBlobNetwork.m
  3. // RNFetchBlob
  4. //
  5. // Created by wkh237 on 2016/6/6.
  6. // Copyright © 2016 wkh237. All rights reserved.
  7. //
  8. #import "RCTLog.h"
  9. #import <Foundation/Foundation.h>
  10. #import "RCTBridge.h"
  11. #import "RNFetchBlob.h"
  12. #import "RCTEventDispatcher.h"
  13. #import "RNFetchBlobFS.h"
  14. #import "RCTRootView.h"
  15. #import "RNFetchBlobNetwork.h"
  16. #import "RNFetchBlobConst.h"
  17. #import "RNFetchBlobReqBuilder.h"
  18. #import "IOS7Polyfill.h"
  19. #import <CommonCrypto/CommonDigest.h>
  20. #import "RNFetchBlobProgress.h"
  21. ////////////////////////////////////////
  22. //
  23. // HTTP request handler
  24. //
  25. ////////////////////////////////////////
  26. NSMapTable * taskTable;
  27. NSMapTable * expirationTable;
  28. NSMapTable * cookiesTable;
  29. NSMutableDictionary * progressTable;
  30. NSMutableDictionary * uploadProgressTable;
  31. typedef NS_ENUM(NSUInteger, ResponseFormat) {
  32. UTF8,
  33. BASE64,
  34. AUTO
  35. };
  36. @interface RNFetchBlobNetwork ()
  37. {
  38. BOOL * respFile;
  39. BOOL isNewPart;
  40. BOOL * isIncrement;
  41. NSMutableData * partBuffer;
  42. NSString * destPath;
  43. NSOutputStream * writeStream;
  44. long bodyLength;
  45. NSMutableDictionary * respInfo;
  46. NSInteger respStatus;
  47. NSMutableArray * redirects;
  48. ResponseFormat responseFormat;
  49. }
  50. @end
  51. @implementation RNFetchBlobNetwork
  52. NSOperationQueue *taskQueue;
  53. @synthesize taskId;
  54. @synthesize expectedBytes;
  55. @synthesize receivedBytes;
  56. @synthesize respData;
  57. @synthesize callback;
  58. @synthesize bridge;
  59. @synthesize options;
  60. @synthesize fileTaskCompletionHandler;
  61. @synthesize dataTaskCompletionHandler;
  62. @synthesize error;
  63. // constructor
  64. - (id)init {
  65. self = [super init];
  66. if(taskQueue == nil) {
  67. taskQueue = [[NSOperationQueue alloc] init];
  68. taskQueue.maxConcurrentOperationCount = 10;
  69. }
  70. if(expirationTable == nil)
  71. {
  72. expirationTable = [[NSMapTable alloc] init];
  73. }
  74. if(taskTable == nil)
  75. {
  76. taskTable = [[NSMapTable alloc] init];
  77. }
  78. if(progressTable == nil)
  79. {
  80. progressTable = [[NSMutableDictionary alloc] init];
  81. }
  82. if(uploadProgressTable == nil)
  83. {
  84. uploadProgressTable = [[NSMutableDictionary alloc] init];
  85. }
  86. if(cookiesTable == nil)
  87. {
  88. cookiesTable = [[NSMapTable alloc] init];
  89. }
  90. return self;
  91. }
  92. + (NSArray *) getCookies:(NSString *) url
  93. {
  94. NSString * hostname = [[NSURL URLWithString:url] host];
  95. NSMutableArray * cookies = [NSMutableArray new];
  96. NSArray * list = [cookiesTable objectForKey:hostname];
  97. for(NSHTTPCookie * cookie in list)
  98. {
  99. NSMutableString * cookieStr = [[NSMutableString alloc] init];
  100. [cookieStr appendString:cookie.name];
  101. [cookieStr appendString:@"="];
  102. [cookieStr appendString:cookie.value];
  103. if(cookie.expiresDate == nil) {
  104. [cookieStr appendString:@"; max-age=0"];
  105. }
  106. else {
  107. [cookieStr appendString:@"; expires="];
  108. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  109. [dateFormatter setDateFormat:@"EEE, dd MM yyyy HH:mm:ss ZZZ"];
  110. NSString *strDate = [dateFormatter stringFromDate:cookie.expiresDate];
  111. [cookieStr appendString:strDate];
  112. }
  113. [cookieStr appendString:@"; domain="];
  114. [cookieStr appendString:hostname];
  115. [cookieStr appendString:@"; path="];
  116. [cookieStr appendString:cookie.path];
  117. if (cookie.isSecure) {
  118. [cookieStr appendString:@"; secure"];
  119. }
  120. if (cookie.isHTTPOnly) {
  121. [cookieStr appendString:@"; httponly"];
  122. }
  123. [cookies addObject:cookieStr];
  124. }
  125. return cookies;
  126. }
  127. + (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config
  128. {
  129. [progressTable setValue:config forKey:taskId];
  130. }
  131. + (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config
  132. {
  133. [uploadProgressTable setValue:config forKey:taskId];
  134. }
  135. // removing case from headers
  136. + (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers
  137. {
  138. NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init];
  139. for(NSString * key in headers) {
  140. [mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]];
  141. }
  142. return mheaders;
  143. }
  144. - (NSString *)md5:(NSString *)input {
  145. const char* str = [input UTF8String];
  146. unsigned char result[CC_MD5_DIGEST_LENGTH];
  147. CC_MD5(str, (CC_LONG)strlen(str), result);
  148. NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
  149. for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
  150. [ret appendFormat:@"%02x",result[i]];
  151. }
  152. return ret;
  153. }
  154. // send HTTP request
  155. - (void) sendRequest:(__weak NSDictionary * _Nullable )options
  156. contentLength:(long) contentLength
  157. bridge:(RCTBridge * _Nullable)bridgeRef
  158. taskId:(NSString * _Nullable)taskId
  159. withRequest:(__weak NSURLRequest * _Nullable)req
  160. callback:(_Nullable RCTResponseSenderBlock) callback
  161. {
  162. self.taskId = taskId;
  163. self.respData = [[NSMutableData alloc] initWithLength:0];
  164. self.callback = callback;
  165. self.bridge = bridgeRef;
  166. self.expectedBytes = 0;
  167. self.receivedBytes = 0;
  168. self.options = options;
  169. isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue];
  170. redirects = [[NSMutableArray alloc] init];
  171. if(req.URL != nil)
  172. [redirects addObject:req.URL.absoluteString];
  173. // set response format
  174. NSString * rnfbResp = [req.allHTTPHeaderFields valueForKey:@"RNFB-Response"];
  175. if([[rnfbResp lowercaseString] isEqualToString:@"base64"])
  176. responseFormat = BASE64;
  177. else if([[rnfbResp lowercaseString] isEqualToString:@"utf8"])
  178. responseFormat = UTF8;
  179. else
  180. responseFormat = AUTO;
  181. NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
  182. NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
  183. NSString * key = [self.options valueForKey:CONFIG_KEY];
  184. __block NSURLSession * session;
  185. bodyLength = contentLength;
  186. // the session trust any SSL certification
  187. // NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
  188. NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
  189. // set request timeout
  190. float timeout = [options valueForKey:@"timeout"] == nil ? -1 : [[options valueForKey:@"timeout"] floatValue];
  191. if(timeout > 0)
  192. {
  193. defaultConfigObject.timeoutIntervalForRequest = timeout/1000;
  194. }
  195. defaultConfigObject.HTTPMaximumConnectionsPerHost = 10;
  196. session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
  197. if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
  198. {
  199. respFile = YES;
  200. NSString* cacheKey = taskId;
  201. if (key != nil) {
  202. cacheKey = [self md5:key];
  203. if (cacheKey == nil) {
  204. cacheKey = taskId;
  205. }
  206. destPath = [RNFetchBlobFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]];
  207. if ([[NSFileManager defaultManager] fileExistsAtPath:destPath]) {
  208. callback(@[[NSNull null], RESP_TYPE_PATH, destPath]);
  209. return;
  210. }
  211. }
  212. if(path != nil)
  213. destPath = path;
  214. else
  215. destPath = [RNFetchBlobFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]];
  216. }
  217. else
  218. {
  219. respData = [[NSMutableData alloc] init];
  220. respFile = NO;
  221. }
  222. __block NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
  223. [taskTable setObject:task forKey:taskId];
  224. [task resume];
  225. // network status indicator
  226. if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
  227. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
  228. __block UIApplication * app = [UIApplication sharedApplication];
  229. // #115 handling task expired when application entering backgound for a long time
  230. [app beginBackgroundTaskWithName:taskId expirationHandler:^{
  231. NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
  232. [expirationTable setObject:task forKey:taskId];
  233. [app endBackgroundTask:task];
  234. }];
  235. }
  236. // #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
  237. + (void) emitExpiredTasks
  238. {
  239. NSEnumerator * emu = [expirationTable keyEnumerator];
  240. NSString * key;
  241. while((key = [emu nextObject]))
  242. {
  243. RCTBridge * bridge = [RNFetchBlob getRCTBridge];
  244. NSData * args = @{ @"taskId": key };
  245. [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
  246. }
  247. // emit expired event once
  248. [expirationTable removeAllObjects];
  249. }
  250. ////////////////////////////////////////
  251. //
  252. // NSURLSession delegates
  253. //
  254. ////////////////////////////////////////
  255. #pragma mark NSURLSession delegate methods
  256. #pragma mark - Received Response
  257. // set expected content length on response received
  258. - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
  259. {
  260. expectedBytes = [response expectedContentLength];
  261. NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  262. NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
  263. NSString * respType = @"";
  264. respStatus = statusCode;
  265. if ([response respondsToSelector:@selector(allHeaderFields)])
  266. {
  267. NSDictionary *headers = [httpResponse allHeaderFields];
  268. NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases:@"Content-Type" fromHeaders:headers] lowercaseString];
  269. if(self.isServerPush == NO)
  270. {
  271. self.isServerPush = [[respCType lowercaseString] RNFBContainsString:@"multipart/x-mixed-replace;"];
  272. }
  273. if(self.isServerPush)
  274. {
  275. if(partBuffer != nil)
  276. {
  277. [self.bridge.eventDispatcher
  278. sendDeviceEventWithName:EVENT_SERVER_PUSH
  279. body:@{
  280. @"taskId": taskId,
  281. @"chunk": [partBuffer base64EncodedStringWithOptions:0],
  282. }
  283. ];
  284. }
  285. partBuffer = [[NSMutableData alloc] init];
  286. completionHandler(NSURLSessionResponseAllow);
  287. return;
  288. }
  289. if(respCType != nil)
  290. {
  291. NSArray * extraBlobCTypes = [options objectForKey:CONFIG_EXTRA_BLOB_CTYPE];
  292. if([respCType RNFBContainsString:@"text/"])
  293. {
  294. respType = @"text";
  295. }
  296. else if([respCType RNFBContainsString:@"application/json"])
  297. {
  298. respType = @"json";
  299. }
  300. // If extra blob content type is not empty, check if response type matches
  301. else if( extraBlobCTypes != nil) {
  302. for(NSString * substr in extraBlobCTypes)
  303. {
  304. if([respCType RNFBContainsString:[substr lowercaseString]])
  305. {
  306. respType = @"blob";
  307. respFile = YES;
  308. destPath = [RNFetchBlobFS getTempPath:taskId withExtension:nil];
  309. break;
  310. }
  311. }
  312. }
  313. else
  314. {
  315. respType = @"blob";
  316. // for XMLHttpRequest, switch response data handling strategy automatically
  317. if([options valueForKey:@"auto"] == YES) {
  318. respFile = YES;
  319. destPath = [RNFetchBlobFS getTempPath:taskId withExtension:@""];
  320. }
  321. }
  322. }
  323. else
  324. respType = @"text";
  325. respInfo = @{
  326. @"taskId": taskId,
  327. @"state": @"2",
  328. @"headers": headers,
  329. @"redirects": redirects,
  330. @"respType" : respType,
  331. @"timeout" : @NO,
  332. @"status": [NSString stringWithFormat:@"%d", statusCode ]
  333. };
  334. #pragma mark - handling cookies
  335. // # 153 get cookies
  336. if(response.URL != nil)
  337. {
  338. NSArray<NSHTTPCookie *> * cookies = [NSHTTPCookie cookiesWithResponseHeaderFields: headers forURL:response.URL];
  339. if(cookies != nil && [cookies count] > 0) {
  340. [cookiesTable setObject:cookies forKey:response.URL.host];
  341. }
  342. }
  343. [self.bridge.eventDispatcher
  344. sendDeviceEventWithName: EVENT_STATE_CHANGE
  345. body:respInfo
  346. ];
  347. headers = nil;
  348. respInfo = nil;
  349. }
  350. else
  351. NSLog(@"oops");
  352. if(respFile == YES)
  353. {
  354. @try{
  355. NSFileManager * fm = [NSFileManager defaultManager];
  356. NSString * folder = [destPath stringByDeletingLastPathComponent];
  357. if(![fm fileExistsAtPath:folder])
  358. {
  359. [fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil];
  360. }
  361. BOOL appendToExistingFile = [destPath RNFBContainsString:@"?append=true"];
  362. // For solving #141 append response data if the file already exists
  363. // base on PR#139 @kejinliang
  364. if(appendToExistingFile)
  365. {
  366. destPath = [destPath stringByReplacingOccurrencesOfString:@"?append=true" withString:@""];
  367. }
  368. if (![fm fileExistsAtPath:destPath])
  369. {
  370. [fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil];
  371. }
  372. writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:YES];
  373. [writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
  374. [writeStream open];
  375. }
  376. @catch(NSException * ex)
  377. {
  378. NSLog(@"write file error");
  379. }
  380. }
  381. completionHandler(NSURLSessionResponseAllow);
  382. }
  383. // download progress handler
  384. - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
  385. {
  386. // For #143 handling multipart/x-mixed-replace response
  387. if(self.isServerPush)
  388. {
  389. [partBuffer appendData:data];
  390. return ;
  391. }
  392. NSNumber * received = [NSNumber numberWithLong:[data length]];
  393. receivedBytes += [received longValue];
  394. NSString * chunkString = @"";
  395. if(isIncrement == YES)
  396. {
  397. chunkString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  398. }
  399. if(respFile == NO)
  400. {
  401. [respData appendData:data];
  402. }
  403. else
  404. {
  405. [writeStream write:[data bytes] maxLength:[data length]];
  406. }
  407. RNFetchBlobProgress * pconfig = [progressTable valueForKey:taskId];
  408. if(expectedBytes == 0)
  409. return;
  410. NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
  411. if(pconfig != nil && [pconfig shouldReport:now])
  412. {
  413. [self.bridge.eventDispatcher
  414. sendDeviceEventWithName:EVENT_PROGRESS
  415. body:@{
  416. @"taskId": taskId,
  417. @"written": [NSString stringWithFormat:@"%d", receivedBytes],
  418. @"total": [NSString stringWithFormat:@"%d", expectedBytes],
  419. @"chunk": chunkString
  420. }
  421. ];
  422. }
  423. received = nil;
  424. }
  425. - (void) URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable NSError *)error
  426. {
  427. if([session isEqual:session])
  428. session = nil;
  429. }
  430. - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
  431. {
  432. self.error = error;
  433. NSString * errMsg = [NSNull null];
  434. NSString * respStr = [NSNull null];
  435. NSString * rnfbRespType = @"";
  436. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  437. if(respInfo == nil)
  438. {
  439. respInfo = [NSNull null];
  440. }
  441. if(error != nil)
  442. {
  443. errMsg = [error localizedDescription];
  444. }
  445. // else
  446. // {
  447. if(respFile == YES)
  448. {
  449. [writeStream close];
  450. rnfbRespType = RESP_TYPE_PATH;
  451. respStr = destPath;
  452. }
  453. // base64 response
  454. else {
  455. // #73 fix unicode data encoding issue :
  456. // when response type is BASE64, we should first try to encode the response data to UTF8 format
  457. // if it turns out not to be `nil` that means the response data contains valid UTF8 string,
  458. // in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding.
  459. NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
  460. if(responseFormat == BASE64)
  461. {
  462. rnfbRespType = RESP_TYPE_BASE64;
  463. respStr = [respData base64EncodedStringWithOptions:0];
  464. }
  465. else if (responseFormat == UTF8)
  466. {
  467. rnfbRespType = RESP_TYPE_UTF8;
  468. respStr = utf8;
  469. }
  470. else
  471. {
  472. if(utf8 != nil)
  473. {
  474. rnfbRespType = RESP_TYPE_UTF8;
  475. respStr = utf8;
  476. }
  477. else
  478. {
  479. rnfbRespType = RESP_TYPE_BASE64;
  480. respStr = [respData base64EncodedStringWithOptions:0];
  481. }
  482. }
  483. }
  484. // }
  485. callback(@[ errMsg, rnfbRespType, respStr]);
  486. @synchronized(taskTable, uploadProgressTable, progressTable)
  487. {
  488. if([taskTable objectForKey:taskId] == nil)
  489. NSLog(@"object released by ARC.");
  490. else
  491. [taskTable removeObjectForKey:taskId];
  492. [uploadProgressTable removeObjectForKey:taskId];
  493. [progressTable removeObjectForKey:taskId];
  494. }
  495. respData = nil;
  496. receivedBytes = 0;
  497. [session finishTasksAndInvalidate];
  498. }
  499. // upload progress handler
  500. - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite
  501. {
  502. RNFetchBlobProgress * pconfig = [uploadProgressTable valueForKey:taskId];
  503. if(totalBytesExpectedToWrite == 0)
  504. return;
  505. NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
  506. if(pconfig != nil && [pconfig shouldReport:now]) {
  507. [self.bridge.eventDispatcher
  508. sendDeviceEventWithName:EVENT_PROGRESS_UPLOAD
  509. body:@{
  510. @"taskId": taskId,
  511. @"written": [NSString stringWithFormat:@"%d", totalBytesWritten],
  512. @"total": [NSString stringWithFormat:@"%d", totalBytesExpectedToWrite]
  513. }
  514. ];
  515. }
  516. }
  517. + (void) cancelRequest:(NSString *)taskId
  518. {
  519. NSURLSessionDataTask * task = [taskTable objectForKey:taskId];
  520. if(task != nil && task.state == NSURLSessionTaskStateRunning)
  521. [task cancel];
  522. }
  523. - (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable credantial))completionHandler
  524. {
  525. if([options valueForKey:CONFIG_TRUSTY] != nil)
  526. {
  527. completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
  528. }
  529. else
  530. {
  531. NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  532. __block NSURLCredential *credential = nil;
  533. if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
  534. {
  535. credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
  536. if (credential) {
  537. disposition = NSURLSessionAuthChallengeUseCredential;
  538. } else {
  539. disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  540. }
  541. }
  542. else
  543. {
  544. disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
  545. RCTLogWarn(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
  546. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  547. }
  548. if (completionHandler) {
  549. completionHandler(disposition, credential);
  550. }
  551. }
  552. }
  553. - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
  554. {
  555. NSLog(@"sess done in background");
  556. }
  557. - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler
  558. {
  559. if(request.URL != nil)
  560. [redirects addObject:[request.URL absoluteString]];
  561. completionHandler(request);
  562. }
  563. @end