Skip to content

Commit 3ec4025

Browse files
authored
Merge pull request #27 from Vydia/ios-responsebody-refactor
a little refactoring of _responsesData
2 parents 3ac2b0d + f9dcbc0 commit 3ec4025

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

ios/VydiaRNFileUploader.m

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#import <React/RCTBridgeModule.h>
1313

1414
@interface VydiaRNFileUploader : RCTEventEmitter <RCTBridgeModule, NSURLSessionTaskDelegate>
15+
{
16+
NSMutableDictionary *_responsesData;
17+
}
1518
@end
1619

1720
@implementation VydiaRNFileUploader
@@ -23,18 +26,12 @@ @implementation VydiaRNFileUploader
2326
static RCTEventEmitter* staticEventEmitter = nil;
2427
static NSString *BACKGROUND_SESSION_ID = @"VydiaRNFileUploader";
2528
NSURLSession *_urlSession = nil;
26-
NSMutableDictionary *_responsesData = nil;
27-
28-
+(void)initialize {
29-
if(!_responsesData) {
30-
_responsesData = [NSMutableDictionary dictionary];
31-
}
32-
}
3329

3430
-(id) init {
3531
self = [super init];
3632
if (self) {
3733
staticEventEmitter = self;
34+
_responsesData = [NSMutableDictionary dictionary];
3835
}
3936
return self;
4037
}
@@ -165,19 +162,18 @@ - (void)URLSession:(NSURLSession *)session
165162
if (response != nil)
166163
{
167164
[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-
179165
}
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+
181177
if (error == nil)
182178
{
183179
[self _sendEventWithName:@"RNFileUploader-completed" body:data];

0 commit comments

Comments
 (0)