Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
Fix IOS request timeout issue #368 by change default request setting …
Browse files Browse the repository at this point in the history
…to defaultSessionConfiguration, and make backgroundSessionConfigurationWithIdentifier optional
  • Loading branch information
wkh237 committed Jun 26, 2017
1 parent 1d4e69c commit 2c16a94
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions ios/RNFetchBlobNetwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ @interface RNFetchBlobNetwork ()
NSMutableArray * redirects;
ResponseFormat responseFormat;
BOOL * followRedirect;
BOOL backgroundTask;
}

@end
Expand Down Expand Up @@ -168,6 +169,8 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
self.expectedBytes = 0;
self.receivedBytes = 0;
self.options = options;

backgroundTask = [options valueForKey:@"IOSBackgroundTask"] == nil ? NO : [[options valueForKey:@"IOSBackgroundTask"] boolValue];
followRedirect = [options valueForKey:@"followRedirect"] == nil ? YES : [[options valueForKey:@"followRedirect"] boolValue];
isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue];
redirects = [[NSMutableArray alloc] init];
Expand All @@ -192,13 +195,12 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options

// the session trust any SSL certification
NSURLSessionConfiguration *defaultConfigObject;
if(!followRedirect)
{
defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
}
else

defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];

if(backgroundTask)
{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
}

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

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

}

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

0 comments on commit 2c16a94

Please sign in to comment.