@kesha-antonov/react-native-background-downloader 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/ios/RNBackgroundDownloader.m +15 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,7 +221,9 @@ An object containing options properties
|
|
|
221
221
|
|
|
222
222
|
### `checkForExistingDownloads()`
|
|
223
223
|
|
|
224
|
-
Checks for downloads that ran in background while you app was terminated.
|
|
224
|
+
Checks for downloads that ran in background while you app was terminated. And also forces them to resume downloads.
|
|
225
|
+
|
|
226
|
+
Recommended to run at the init stage of the app.
|
|
225
227
|
|
|
226
228
|
**returns**
|
|
227
229
|
|
|
@@ -111,18 +111,14 @@ RCT_EXPORT_MODULE();
|
|
|
111
111
|
|
|
112
112
|
// NOTE: FIXES HANGING DOWNLOADS WHEN GOING TO BG
|
|
113
113
|
- (void) resumeTasks:(NSNotification *) note {
|
|
114
|
-
NSLog(@"[RNBackgroundDownloader] - [resumeTasks]
|
|
114
|
+
NSLog(@"[RNBackgroundDownloader] - [resumeTasks]");
|
|
115
115
|
@synchronized (sharedLock) {
|
|
116
116
|
[urlSession getTasksWithCompletionHandler:^(NSArray<NSURLSessionDataTask *> * _Nonnull dataTasks, NSArray<NSURLSessionUploadTask *> * _Nonnull uploadTasks, NSArray<NSURLSessionDownloadTask *> * _Nonnull downloadTasks) {
|
|
117
|
-
NSLog(@"[RNBackgroundDownloader] - [resumeTasks] 2");
|
|
118
117
|
for (NSURLSessionDownloadTask *task in downloadTasks) {
|
|
119
|
-
NSLog(@"[RNBackgroundDownloader] - [resumeTasks] 3 - state - %@", [NSNumber numberWithInt:task.state]);
|
|
120
118
|
// running - 0
|
|
121
119
|
// suspended - 1
|
|
122
120
|
// canceling - 2
|
|
123
121
|
// completed - 3
|
|
124
|
-
NSLog(@"[RNBackgroundDownloader] - [resumeTasks] 4 - totalBytes - %@", [NSNumber numberWithInt:task.countOfBytesExpectedToReceive]);
|
|
125
|
-
NSLog(@"[RNBackgroundDownloader] - [resumeTasks] 5 - bytesWritten - %@", [NSNumber numberWithInt:task.countOfBytesReceived]);
|
|
126
122
|
|
|
127
123
|
if (task.state == NSURLSessionTaskStateRunning) {
|
|
128
124
|
[task suspend]; // PAUSE
|
|
@@ -276,8 +272,8 @@ RCT_EXPORT_METHOD(checkForExistingDownloads: (RCTPromiseResolveBlock)resolve rej
|
|
|
276
272
|
NSURLSessionDownloadTask __strong *task = foundTask;
|
|
277
273
|
RNBGDTaskConfig *taskConfig = taskToConfigMap[@(task.taskIdentifier)];
|
|
278
274
|
if (taskConfig) {
|
|
279
|
-
if (task.state == NSURLSessionTaskStateCompleted && task.countOfBytesReceived < task.countOfBytesExpectedToReceive) {
|
|
280
|
-
if (task.error && task.error.
|
|
275
|
+
if ((task.state == NSURLSessionTaskStateCompleted || task.state == NSURLSessionTaskStateSuspended) && task.countOfBytesReceived < task.countOfBytesExpectedToReceive) {
|
|
276
|
+
if (task.error && task.error.userInfo[NSURLSessionDownloadTaskResumeData] != nil) {
|
|
281
277
|
task = [urlSession downloadTaskWithResumeData:task.error.userInfo[NSURLSessionDownloadTaskResumeData]];
|
|
282
278
|
} else {
|
|
283
279
|
task = [urlSession downloadTaskWithURL:task.currentRequest.URL];
|
|
@@ -354,6 +350,7 @@ RCT_EXPORT_METHOD(completeHandler:(nonnull NSString *)jobId
|
|
|
354
350
|
@synchronized (sharedLock) {
|
|
355
351
|
RNBGDTaskConfig *taskCofig = taskToConfigMap[@(downloadTask.taskIdentifier)];
|
|
356
352
|
if (taskCofig != nil) {
|
|
353
|
+
// NSLog(@"[RNBackgroundDownloader] - [didWriteData] destination - %@", taskCofig.destination);
|
|
357
354
|
if (!taskCofig.reportedBegin) {
|
|
358
355
|
NSDictionary *responseHeaders = ((NSHTTPURLResponse *)downloadTask.response).allHeaderFields;
|
|
359
356
|
if (self.bridge) {
|
|
@@ -388,11 +385,18 @@ RCT_EXPORT_METHOD(completeHandler:(nonnull NSString *)jobId
|
|
|
388
385
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
|
389
386
|
NSLog(@"[RNBackgroundDownloader] - [didCompleteWithError]");
|
|
390
387
|
@synchronized (sharedLock) {
|
|
388
|
+
if (error == nil)
|
|
389
|
+
return;
|
|
390
|
+
|
|
391
391
|
RNBGDTaskConfig *taskCofig = taskToConfigMap[@(task.taskIdentifier)];
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
if (taskCofig == nil)
|
|
393
|
+
return;
|
|
394
|
+
|
|
395
|
+
if (self.bridge) {
|
|
396
|
+
[self sendEventWithName:@"downloadFailed" body:@{@"id": taskCofig.id, @"error": [error localizedDescription]}];
|
|
397
|
+
}
|
|
398
|
+
// IF WE CAN'T RESUME TO DOWNLOAD LATER
|
|
399
|
+
if (error.userInfo[NSURLSessionDownloadTaskResumeData] == nil) {
|
|
396
400
|
[self removeTaskFromMap:task];
|
|
397
401
|
}
|
|
398
402
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kesha-antonov/react-native-background-downloader",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|