|
@@ -13,7 +13,6 @@
|
13
|
13
|
#import "RNFetchBlob.h"
|
14
|
14
|
#import "RNFetchBlobConst.h"
|
15
|
15
|
#import "RNFetchBlobProgress.h"
|
16
|
|
-#import "RNFetchBlobRequest.h"
|
17
|
16
|
|
18
|
17
|
#if __has_include(<React/RCTAssert.h>)
|
19
|
18
|
#import <React/RCTRootView.h>
|
|
@@ -46,23 +45,21 @@ static void initialize_tables() {
|
46
|
45
|
|
47
|
46
|
@implementation RNFetchBlobNetwork
|
48
|
47
|
|
49
|
|
-NSOperationQueue *taskQueue;
|
50
|
|
-NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
|
51
|
48
|
|
52
|
49
|
- (id)init {
|
53
|
50
|
self = [super init];
|
54
|
51
|
if (self) {
|
55
|
|
- requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
|
|
52
|
+ self.requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
|
56
|
53
|
|
57
|
|
- taskQueue = [[NSOperationQueue alloc] init];
|
58
|
|
- taskQueue.qualityOfService = NSQualityOfServiceUtility;
|
59
|
|
- taskQueue.maxConcurrentOperationCount = 10;
|
|
54
|
+ self.taskQueue = [[NSOperationQueue alloc] init];
|
|
55
|
+ self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
|
|
56
|
+ self.taskQueue.maxConcurrentOperationCount = 10;
|
60
|
57
|
}
|
61
|
58
|
|
62
|
59
|
return self;
|
63
|
60
|
}
|
64
|
61
|
|
65
|
|
-+ (instancetype)sharedInstance {
|
|
62
|
++ (RNFetchBlobNetwork* _Nullable)sharedInstance {
|
66
|
63
|
static id _sharedInstance = nil;
|
67
|
64
|
static dispatch_once_t onceToken;
|
68
|
65
|
dispatch_once(&onceToken, ^{
|
|
@@ -85,11 +82,11 @@ NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
|
85
|
82
|
bridge:bridgeRef
|
86
|
83
|
taskId:taskId
|
87
|
84
|
withRequest:req
|
88
|
|
- taskOperationQueue:taskQueue
|
|
85
|
+ taskOperationQueue:[self sharedInstance].taskQueue
|
89
|
86
|
callback:callback];
|
90
|
87
|
|
91
|
88
|
@synchronized([RNFetchBlobNetwork class]) {
|
92
|
|
- [requestsTable setObject:request forKey:taskId];
|
|
89
|
+ [[self sharedInstance].requestsTable setObject:request forKey:taskId];
|
93
|
90
|
}
|
94
|
91
|
}
|
95
|
92
|
|
|
@@ -97,7 +94,7 @@ NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
|
97
|
94
|
{
|
98
|
95
|
if (config) {
|
99
|
96
|
@synchronized ([RNFetchBlobNetwork class]) {
|
100
|
|
- [requestsTable objectForKey:taskId].progressConfig = config;
|
|
97
|
+ [[self sharedInstance].requestsTable objectForKey:taskId].progressConfig = config;
|
101
|
98
|
}
|
102
|
99
|
}
|
103
|
100
|
}
|
|
@@ -106,7 +103,7 @@ NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
|
106
|
103
|
{
|
107
|
104
|
if (config) {
|
108
|
105
|
@synchronized ([RNFetchBlobNetwork class]) {
|
109
|
|
- [requestsTable objectForKey:taskId].uploadProgressConfig = config;
|
|
106
|
+ [[self sharedInstance].requestsTable objectForKey:taskId].uploadProgressConfig = config;
|
110
|
107
|
}
|
111
|
108
|
}
|
112
|
109
|
}
|
|
@@ -148,7 +145,7 @@ NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
|
148
|
145
|
NSURLSessionDataTask * task;
|
149
|
146
|
|
150
|
147
|
@synchronized ([RNFetchBlobNetwork class]) {
|
151
|
|
- task = [requestsTable objectForKey:taskId].task;
|
|
148
|
+ task = [[self sharedInstance].requestsTable objectForKey:taskId].task;
|
152
|
149
|
}
|
153
|
150
|
|
154
|
151
|
if(task && task.state == NSURLSessionTaskStateRunning) {
|