@@ -21,9 +21,9 @@ @implementation RNBackgroundDownload {
21
21
NSMutableDictionary <NSString *, NSURLSessionDownloadTask *> *idToTaskMap;
22
22
NSMutableDictionary <NSString *, NSData *> *idToResumeDataMap;
23
23
NSMutableDictionary <NSString *, NSNumber *> *idToPercentMap;
24
+ NSMutableDictionary <NSString *, NSDictionary *> *progressReports;
24
25
NSOperationQueue *downloadOperationsQueue;
25
26
NSDate *lastProgressReport;
26
- NSMutableArray <NSDictionary *> *progressReports;
27
27
}
28
28
29
29
RCT_EXPORT_MODULE ();
@@ -68,7 +68,7 @@ - (id) init {
68
68
NSString *sessonIdentifier = [bundleIdentifier stringByAppendingString: @" .backgrounddownloadtask" ];
69
69
sessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: sessonIdentifier];
70
70
downloadOperationsQueue = [[NSOperationQueue alloc ] init ];
71
- progressReports = [[NSMutableArray alloc ] init ];
71
+ progressReports = [[NSMutableDictionary alloc ] init ];
72
72
lastProgressReport = [[NSDate alloc ] init ];
73
73
}
74
74
return self;
@@ -220,14 +220,14 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
220
220
NSNumber *prevPercent = idToPercentMap[taskCofig.id ];
221
221
NSNumber *percent = [NSNumber numberWithFloat: (float )totalBytesWritten/(float )totalBytesExpectedToWrite];
222
222
if ([percent floatValue ] - [prevPercent floatValue ] > 0 .01f ) {
223
- [ progressReports addObject: @{@" id" : taskCofig.id , @" written" : [NSNumber numberWithLongLong: totalBytesWritten], @" total" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite], @" percent" : percent}] ;
223
+ progressReports[taskCofig. id ] = @{@" id" : taskCofig.id , @" written" : [NSNumber numberWithLongLong: totalBytesWritten], @" total" : [NSNumber numberWithLongLong: totalBytesExpectedToWrite], @" percent" : percent};
224
224
idToPercentMap[taskCofig.id ] = percent;
225
225
}
226
226
227
227
NSDate *now = [[NSDate alloc ] init ];
228
228
if ([now timeIntervalSinceDate: lastProgressReport] > 1.5 && progressReports.count > 0 ) {
229
229
if (self.bridge ) {
230
- [self sendEventWithName: @" downloadProgress" body: progressReports];
230
+ [self sendEventWithName: @" downloadProgress" body: [ progressReports allValues ] ];
231
231
}
232
232
lastProgressReport = now;
233
233
[progressReports removeAllObjects ];
0 commit comments