Skip to content

Commit 2c16a94

Browse files
committed
Fix IOS request timeout issue wkh237#368 by change default request setting to defaultSessionConfiguration, and make backgroundSessionConfigurationWithIdentifier optional
1 parent 1d4e69c commit 2c16a94

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

ios/RNFetchBlobNetwork.m

+8-14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ @interface RNFetchBlobNetwork ()
8282
NSMutableArray * redirects;
8383
ResponseFormat responseFormat;
8484
BOOL * followRedirect;
85+
BOOL backgroundTask;
8586
}
8687

8788
@end
@@ -168,6 +169,8 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
168169
self.expectedBytes = 0;
169170
self.receivedBytes = 0;
170171
self.options = options;
172+
173+
backgroundTask = [options valueForKey:@"IOSBackgroundTask"] == nil ? NO : [[options valueForKey:@"IOSBackgroundTask"] boolValue];
171174
followRedirect = [options valueForKey:@"followRedirect"] == nil ? YES : [[options valueForKey:@"followRedirect"] boolValue];
172175
isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue];
173176
redirects = [[NSMutableArray alloc] init];
@@ -192,13 +195,12 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
192195

193196
// the session trust any SSL certification
194197
NSURLSessionConfiguration *defaultConfigObject;
195-
if(!followRedirect)
196-
{
197-
defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
198-
}
199-
else
198+
199+
defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
200+
201+
if(backgroundTask)
200202
{
201-
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
203+
defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
202204
}
203205

204206
// set request timeout
@@ -247,14 +249,6 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
247249
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
248250
__block UIApplication * app = [UIApplication sharedApplication];
249251

250-
// #115 handling task expired when application entering backgound for a long time
251-
UIBackgroundTaskIdentifier tid = [app beginBackgroundTaskWithName:taskId expirationHandler:^{
252-
NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
253-
[expirationTable setObject:task forKey:taskId];
254-
// comment out this one as it might cause app crash #271
255-
// [app endBackgroundTask:tid];
256-
}];
257-
258252
}
259253

260254
// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled

0 commit comments

Comments
 (0)