Skip to content

Commit 78c092d

Browse files
committed
Added didWriteData method for send progress data
1 parent 36bd359 commit 78c092d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ios/ReactNativeBlobUtilRequest.mm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,5 +541,27 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPe
541541
}
542542
}
543543

544+
// NSURLSessionDownloadTask delegates
545+
546+
#pragma mark NSURLSessionDownloadTask delegate methods
547+
548+
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
549+
if (totalBytesExpectedToWrite == 0) {
550+
return;
551+
}
552+
553+
NSNumber * now =[NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
554+
if ([self.progressConfig shouldReport:now]) {
555+
[self.bridge.eventDispatcher
556+
sendDeviceEventWithName:EVENT_PROGRESS
557+
body:@{
558+
@"taskId": taskId,
559+
@"written": [NSString stringWithFormat:@"%lld", (long long) totalBytesWritten],
560+
@"total": [NSString stringWithFormat:@"%lld", (long long) totalBytesExpectedToWrite]
561+
}
562+
];
563+
}
564+
}
565+
544566

545567
@end

0 commit comments

Comments
 (0)