|
@@ -109,11 +109,11 @@ NSOperationQueue *taskQueue;
|
109
|
109
|
}
|
110
|
110
|
|
111
|
111
|
// send HTTP request
|
112
|
|
-- (void) sendRequest:(NSDictionary * _Nullable )options
|
|
112
|
+- (void) sendRequest:(__weak NSDictionary * _Nullable )options
|
113
|
113
|
contentLength:(long) contentLength
|
114
|
114
|
bridge:(RCTBridge * _Nullable)bridgeRef
|
115
|
115
|
taskId:(NSString * _Nullable)taskId
|
116
|
|
- withRequest:(NSURLRequest * _Nullable)req
|
|
116
|
+ withRequest:(__weak NSURLRequest * _Nullable)req
|
117
|
117
|
callback:(_Nullable RCTResponseSenderBlock) callback
|
118
|
118
|
{
|
119
|
119
|
self.taskId = taskId;
|
|
@@ -127,19 +127,19 @@ NSOperationQueue *taskQueue;
|
127
|
127
|
NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
|
128
|
128
|
NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
|
129
|
129
|
NSString * key = [self.options valueForKey:CONFIG_KEY];
|
130
|
|
- NSURLSession * session;
|
|
130
|
+ __block NSURLSession * session;
|
131
|
131
|
|
132
|
132
|
bodyLength = contentLength;
|
133
|
133
|
|
134
|
134
|
// the session trust any SSL certification
|
135
|
135
|
|
|
136
|
+
|
136
|
137
|
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
137
|
138
|
if([options valueForKey:@"timeout"] != nil)
|
138
|
139
|
{
|
139
|
140
|
defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey:@"timeout"] floatValue];
|
140
|
141
|
}
|
141
|
142
|
session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
|
142
|
|
-
|
143
|
143
|
if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
|
144
|
144
|
{
|
145
|
145
|
respFile = YES;
|
|
@@ -229,10 +229,13 @@ NSOperationQueue *taskQueue;
|
229
|
229
|
@"timeout" : @NO,
|
230
|
230
|
@"status": [NSString stringWithFormat:@"%d", statusCode ]
|
231
|
231
|
};
|
|
232
|
+
|
232
|
233
|
[self.bridge.eventDispatcher
|
233
|
234
|
sendDeviceEventWithName: EVENT_STATE_CHANGE
|
234
|
235
|
body:respInfo
|
235
|
|
- ];
|
|
236
|
+ ];
|
|
237
|
+ headers = nil;
|
|
238
|
+ respInfo = nil;
|
236
|
239
|
}
|
237
|
240
|
|
238
|
241
|
if(respFile == YES)
|
|
@@ -259,7 +262,8 @@ NSOperationQueue *taskQueue;
|
259
|
262
|
// download progress handler
|
260
|
263
|
- (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
|
261
|
264
|
{
|
262
|
|
- receivedBytes += [data length];
|
|
265
|
+ NSNumber * received = [NSNumber numberWithLong:[data length]];
|
|
266
|
+ receivedBytes += [received longValue];
|
263
|
267
|
if(respFile == NO)
|
264
|
268
|
{
|
265
|
269
|
[respData appendData:data];
|
|
@@ -280,10 +284,18 @@ NSOperationQueue *taskQueue;
|
280
|
284
|
}
|
281
|
285
|
];
|
282
|
286
|
}
|
|
287
|
+ received = nil;
|
283
|
288
|
|
284
|
289
|
}
|
285
|
290
|
|
286
|
|
-- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
|
291
|
+- (void) URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable NSError *)error
|
|
292
|
+{
|
|
293
|
+ if([session isEqual:session])
|
|
294
|
+ session = nil;
|
|
295
|
+}
|
|
296
|
+
|
|
297
|
+- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
|
|
298
|
+{
|
287
|
299
|
|
288
|
300
|
self.error = error;
|
289
|
301
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
|
|
@@ -313,6 +325,9 @@ NSOperationQueue *taskQueue;
|
313
|
325
|
[taskTable removeObjectForKey:taskId];
|
314
|
326
|
[uploadProgressTable removeObjectForKey:taskId];
|
315
|
327
|
[progressTable removeObjectForKey:taskId];
|
|
328
|
+ respData = nil;
|
|
329
|
+ receivedBytes = 0;
|
|
330
|
+ [session finishTasksAndInvalidate];
|
316
|
331
|
}
|
317
|
332
|
|
318
|
333
|
// upload progress handler
|