@@ -82,6 +82,7 @@ @interface RNFetchBlobNetwork ()
82
82
NSMutableArray * redirects;
83
83
ResponseFormat responseFormat;
84
84
BOOL * followRedirect;
85
+ BOOL backgroundTask;
85
86
}
86
87
87
88
@end
@@ -168,6 +169,8 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
168
169
self.expectedBytes = 0 ;
169
170
self.receivedBytes = 0 ;
170
171
self.options = options;
172
+
173
+ backgroundTask = [options valueForKey: @" IOSBackgroundTask" ] == nil ? NO : [[options valueForKey: @" IOSBackgroundTask" ] boolValue ];
171
174
followRedirect = [options valueForKey: @" followRedirect" ] == nil ? YES : [[options valueForKey: @" followRedirect" ] boolValue ];
172
175
isIncrement = [options valueForKey: @" increment" ] == nil ? NO : [[options valueForKey: @" increment" ] boolValue ];
173
176
redirects = [[NSMutableArray alloc ] init ];
@@ -192,13 +195,12 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
192
195
193
196
// the session trust any SSL certification
194
197
NSURLSessionConfiguration *defaultConfigObject;
195
- if (!followRedirect)
196
- {
197
- defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration ];
198
- }
199
- else
198
+
199
+ defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration ];
200
+
201
+ if (backgroundTask)
200
202
{
201
- NSURLSessionConfiguration * defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: taskId];
203
+ defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: taskId];
202
204
}
203
205
204
206
// set request timeout
@@ -247,14 +249,6 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
247
249
[[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: YES ];
248
250
__block UIApplication * app = [UIApplication sharedApplication ];
249
251
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
-
258
252
}
259
253
260
254
// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
0 commit comments