12
12
#import < React/RCTBridgeModule.h>
13
13
14
14
@interface VydiaRNFileUploader : RCTEventEmitter <RCTBridgeModule, NSURLSessionTaskDelegate >
15
+ {
16
+ NSMutableDictionary *_responsesData;
17
+ }
15
18
@end
16
19
17
20
@implementation VydiaRNFileUploader
@@ -23,18 +26,12 @@ @implementation VydiaRNFileUploader
23
26
static RCTEventEmitter* staticEventEmitter = nil ;
24
27
static NSString *BACKGROUND_SESSION_ID = @" VydiaRNFileUploader" ;
25
28
NSURLSession *_urlSession = nil ;
26
- NSMutableDictionary *_responsesData = nil ;
27
-
28
- +(void )initialize {
29
- if (!_responsesData) {
30
- _responsesData = [NSMutableDictionary dictionary ];
31
- }
32
- }
33
29
34
30
-(id ) init {
35
31
self = [super init ];
36
32
if (self) {
37
33
staticEventEmitter = self;
34
+ _responsesData = [NSMutableDictionary dictionary ];
38
35
}
39
36
return self;
40
37
}
@@ -165,19 +162,18 @@ - (void)URLSession:(NSURLSession *)session
165
162
if (response != nil )
166
163
{
167
164
[data setObject: [NSNumber numberWithInteger: response.statusCode] forKey: @" responseCode" ];
168
-
169
- // Add data that was collected earlier by the didReceiveData method
170
- NSMutableData *responseData = _responsesData[@(task.taskIdentifier)];
171
- if (responseData) {
172
- NSString *response = [[NSString alloc ] initWithData: responseData encoding: NSUTF8StringEncoding];
173
- [data setObject: response forKey: @" responseBody" ];
174
- } else {
175
- [data setObject: [NSNull null ] forKey: @" responseBody" ];
176
- }
177
- [_responsesData removeObjectForKey: @(task.taskIdentifier)];
178
-
179
165
}
180
-
166
+
167
+ // Add data that was collected earlier by the didReceiveData method
168
+ NSMutableData *responseData = _responsesData[@(task.taskIdentifier)];
169
+ [_responsesData removeObjectForKey: @(task.taskIdentifier)];
170
+ if (responseData) {
171
+ NSString *response = [[NSString alloc ] initWithData: responseData encoding: NSUTF8StringEncoding];
172
+ [data setObject: response forKey: @" responseBody" ];
173
+ } else {
174
+ [data setObject: [NSNull null ] forKey: @" responseBody" ];
175
+ }
176
+
181
177
if (error == nil )
182
178
{
183
179
[self _sendEventWithName: @" RNFileUploader-completed" body: data];
0 commit comments