|
@@ -38,7 +38,6 @@ NSMutableDictionary * taskTable;
|
38
|
38
|
@implementation RNFetchBlobNetwork
|
39
|
39
|
|
40
|
40
|
NSOperationQueue *taskQueue;
|
41
|
|
-
|
42
|
41
|
@synthesize taskId;
|
43
|
42
|
@synthesize expectedBytes;
|
44
|
43
|
@synthesize receivedBytes;
|
|
@@ -56,6 +55,7 @@ NSOperationQueue *taskQueue;
|
56
|
55
|
self = [super init];
|
57
|
56
|
if(taskQueue == nil) {
|
58
|
57
|
taskQueue = [[NSOperationQueue alloc] init];
|
|
58
|
+ taskQueue.maxConcurrentOperationCount = 10;
|
59
|
59
|
}
|
60
|
60
|
if(taskTable == nil) {
|
61
|
61
|
taskTable = [[NSMutableDictionary alloc] init];
|
|
@@ -113,7 +113,7 @@ NSOperationQueue *taskQueue;
|
113
|
113
|
// the session trust any SSL certification
|
114
|
114
|
|
115
|
115
|
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
116
|
|
- session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
|
|
116
|
+ session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
|
117
|
117
|
|
118
|
118
|
if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
|
119
|
119
|
{
|
|
@@ -209,15 +209,21 @@ NSOperationQueue *taskQueue;
|
209
|
209
|
|
210
|
210
|
if(respFile == YES)
|
211
|
211
|
{
|
212
|
|
- NSFileManager * fm = [NSFileManager defaultManager];
|
213
|
|
- NSString * folder = [destPath stringByDeletingLastPathComponent];
|
214
|
|
- if(![fm fileExistsAtPath:folder]) {
|
215
|
|
- [fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil];
|
|
212
|
+ @try{
|
|
213
|
+ NSFileManager * fm = [NSFileManager defaultManager];
|
|
214
|
+ NSString * folder = [destPath stringByDeletingLastPathComponent];
|
|
215
|
+ if(![fm fileExistsAtPath:folder]) {
|
|
216
|
+ [fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil];
|
|
217
|
+ }
|
|
218
|
+ [fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil];
|
|
219
|
+ writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:YES];
|
|
220
|
+ [writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
|
221
|
+ [writeStream open];
|
|
222
|
+ }
|
|
223
|
+ @catch(NSException * ex)
|
|
224
|
+ {
|
|
225
|
+ NSLog(@"write file error");
|
216
|
226
|
}
|
217
|
|
- [fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil];
|
218
|
|
- writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:YES];
|
219
|
|
- [writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
220
|
|
- [writeStream open];
|
221
|
227
|
}
|
222
|
228
|
completionHandler(NSURLSessionResponseAllow);
|
223
|
229
|
}
|
|
@@ -255,6 +261,9 @@ NSOperationQueue *taskQueue;
|
255
|
261
|
|
256
|
262
|
if(respFile == YES)
|
257
|
263
|
{
|
|
264
|
+ if(error != nil) {
|
|
265
|
+ NSLog([error localizedDescription]);
|
|
266
|
+ }
|
258
|
267
|
[writeStream close];
|
259
|
268
|
callback(@[error == nil ? [NSNull null] : [error localizedDescription],
|
260
|
269
|
respInfo == nil ? [NSNull null] : respInfo,
|