@@ -79,10 +79,8 @@ - (void)lazyInitSession {
79
79
- (void )removeTaskFromMap : (NSURLSessionTask *)task {
80
80
NSNumber *taskId = @(task.taskIdentifier );
81
81
RNBGDTaskConfig *taskConfig = taskToConfigMap[taskId];
82
- @synchronized (taskToConfigMap) {
83
- [taskToConfigMap removeObjectForKey: taskId];
84
- [[NSUserDefaults standardUserDefaults ] setObject: [self serialize: taskToConfigMap] forKey: ID_TO_CONFIG_MAP_KEY];
85
- }
82
+ [taskToConfigMap removeObjectForKey: taskId];
83
+ [[NSUserDefaults standardUserDefaults ] setObject: [self serialize: taskToConfigMap] forKey: ID_TO_CONFIG_MAP_KEY];
86
84
if (taskConfig) {
87
85
[idToTaskMap removeObjectForKey: taskConfig.id ];
88
86
[idToPercentMap removeObjectForKey: taskConfig.id ];
@@ -123,10 +121,8 @@ + (void)setCompletionHandlerWithIdentifier: (NSString *)identifier completionHan
123
121
124
122
NSURLSessionDownloadTask __strong *task = [urlSession downloadTaskWithRequest: request];
125
123
RNBGDTaskConfig *taskConfig = [[RNBGDTaskConfig alloc ] initWithDictionary: @{@" id" : identifier, @" destination" : destination}];
126
- @synchronized (taskToConfigMap) {
127
- taskToConfigMap[@(task.taskIdentifier)] = taskConfig;
128
- [[NSUserDefaults standardUserDefaults ] setObject: [self serialize: taskToConfigMap] forKey: ID_TO_CONFIG_MAP_KEY];
129
- }
124
+ taskToConfigMap[@(task.taskIdentifier)] = taskConfig;
125
+ [[NSUserDefaults standardUserDefaults ] setObject: [self serialize: taskToConfigMap] forKey: ID_TO_CONFIG_MAP_KEY];
130
126
idToTaskMap[identifier] = task;
131
127
idToPercentMap[identifier] = @0.0 ;
132
128
@@ -216,29 +212,27 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
216
212
}
217
213
218
214
- (void )URLSession : (NSURLSession *)session downloadTask : (NSURLSessionDownloadTask *)downloadTask didWriteData : (int64_t )bytesWritten totalBytesWritten : (int64_t )totalBytesWritten totalBytesExpectedToWrite : (int64_t )totalBytesExpectedToWrite {
219
- @synchronized (self) {
220
- RNBGDTaskConfig *taskCofig = taskToConfigMap[@(downloadTask.taskIdentifier)];
221
- if (taskCofig != nil ) {
222
- if (!taskCofig.reportedBegin ) {
223
- [self sendEventWithName: @" downloadBegin" body: @{@" id" : taskCofig.id , @" expectedBytes" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite]}];
224
- taskCofig.reportedBegin = YES ;
225
- }
226
-
227
- NSNumber *prevPercent = idToPercentMap[taskCofig.id ];
228
- NSNumber *percent = [NSNumber numberWithFloat: (float )totalBytesWritten/(float )totalBytesExpectedToWrite];
229
- if ([percent floatValue ] - [prevPercent floatValue ] > 0 .01f ) {
230
- progressReports[taskCofig.id ] = @{@" id" : taskCofig.id , @" written" : [NSNumber numberWithLongLong: totalBytesWritten], @" total" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite], @" percent" : percent};
231
- idToPercentMap[taskCofig.id ] = percent;
232
- }
233
-
234
- NSDate *now = [[NSDate alloc ] init ];
235
- if ([now timeIntervalSinceDate: lastProgressReport] > 1.5 && progressReports.count > 0 ) {
236
- if (self.bridge ) {
237
- [self sendEventWithName: @" downloadProgress" body: [progressReports allValues ]];
238
- }
239
- lastProgressReport = now;
240
- [progressReports removeAllObjects ];
215
+ RNBGDTaskConfig *taskCofig = taskToConfigMap[@(downloadTask.taskIdentifier)];
216
+ if (taskCofig != nil ) {
217
+ if (!taskCofig.reportedBegin ) {
218
+ [self sendEventWithName: @" downloadBegin" body: @{@" id" : taskCofig.id , @" expectedBytes" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite]}];
219
+ taskCofig.reportedBegin = YES ;
220
+ }
221
+
222
+ NSNumber *prevPercent = idToPercentMap[taskCofig.id ];
223
+ NSNumber *percent = [NSNumber numberWithFloat: (float )totalBytesWritten/(float )totalBytesExpectedToWrite];
224
+ if ([percent floatValue ] - [prevPercent floatValue ] > 0 .01f ) {
225
+ progressReports[taskCofig.id ] = @{@" id" : taskCofig.id , @" written" : [NSNumber numberWithLongLong: totalBytesWritten], @" total" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite], @" percent" : percent};
226
+ idToPercentMap[taskCofig.id ] = percent;
227
+ }
228
+
229
+ NSDate *now = [[NSDate alloc ] init ];
230
+ if ([now timeIntervalSinceDate: lastProgressReport] > 1.5 && progressReports.count > 0 ) {
231
+ if (self.bridge ) {
232
+ [self sendEventWithName: @" downloadProgress" body: [progressReports allValues ]];
241
233
}
234
+ lastProgressReport = now;
235
+ [progressReports removeAllObjects ];
242
236
}
243
237
}
244
238
}
0 commit comments