@kesha-antonov/react-native-background-downloader 4.1.2-alpha.0 → 4.1.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.
|
@@ -49,7 +49,6 @@ static CompletionHandler storedCompletionHandler;
|
|
|
49
49
|
int64_t progressMinBytes;
|
|
50
50
|
NSDate *lastProgressReportedAt;
|
|
51
51
|
BOOL isBridgeListenerInited;
|
|
52
|
-
BOOL isJavascriptLoaded;
|
|
53
52
|
BOOL hasListeners;
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -63,13 +62,6 @@ RCT_EXPORT_MODULE();
|
|
|
63
62
|
|
|
64
63
|
#pragma mark - Helper methods
|
|
65
64
|
|
|
66
|
-
- (BOOL)canSendEvents {
|
|
67
|
-
// Only send events if JavaScript has fully loaded
|
|
68
|
-
// This prevents "Invariant Violation: Failed to call into JavaScript module method"
|
|
69
|
-
// errors that occur when native code tries to send events before the JS bridge is ready
|
|
70
|
-
return isJavascriptLoaded;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
65
|
- (RNBGDTaskConfig *)configForTask:(NSURLSessionTask *)task {
|
|
74
66
|
return taskToConfigMap[@(task.taskIdentifier)];
|
|
75
67
|
}
|
|
@@ -126,11 +118,6 @@ RCT_EXPORT_MODULE();
|
|
|
126
118
|
self = [super initWithDisabledObservation];
|
|
127
119
|
#endif
|
|
128
120
|
if (self) {
|
|
129
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
130
|
-
// TurboModules are lazily initialized when JS first accesses them,
|
|
131
|
-
// so JavaScript is ready when init is called
|
|
132
|
-
isJavascriptLoaded = YES;
|
|
133
|
-
#endif
|
|
134
121
|
[MMKV initializeMMKV:nil];
|
|
135
122
|
mmkv = [MMKV mmkvWithID:@"RNBackgroundDownloader"];
|
|
136
123
|
|
|
@@ -221,11 +208,6 @@ RCT_EXPORT_MODULE();
|
|
|
221
208
|
selector:@selector(handleBridgeHotReload:)
|
|
222
209
|
name:RCTJavaScriptWillStartLoadingNotification
|
|
223
210
|
object:nil];
|
|
224
|
-
|
|
225
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
226
|
-
selector:@selector(handleBridgeJavascriptLoad:)
|
|
227
|
-
name:RCTJavaScriptDidLoadNotification
|
|
228
|
-
object:nil];
|
|
229
211
|
}
|
|
230
212
|
}
|
|
231
213
|
}
|
|
@@ -238,11 +220,6 @@ RCT_EXPORT_MODULE();
|
|
|
238
220
|
}
|
|
239
221
|
}
|
|
240
222
|
|
|
241
|
-
- (void)handleBridgeJavascriptLoad:(NSNotification *) note {
|
|
242
|
-
DLog(nil, @"[RNBackgroundDownloader] - [handleBridgeJavascriptLoad]");
|
|
243
|
-
isJavascriptLoaded = YES;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
223
|
- (void)handleBridgeAppEnterForeground:(NSNotification *) note {
|
|
247
224
|
DLog(nil, @"[RNBackgroundDownloader] - [handleBridgeAppEnterForeground]");
|
|
248
225
|
[self resumeTasks];
|
|
@@ -687,9 +664,7 @@ RCT_EXPORT_METHOD(getExistingDownloadTasks: (RCTPromiseResolveBlock)resolve reje
|
|
|
687
664
|
[self saveFile:taskConfig downloadURL:location error:&error];
|
|
688
665
|
}
|
|
689
666
|
|
|
690
|
-
|
|
691
|
-
[self sendDownloadCompletionEvent:taskConfig task:downloadTask error:error];
|
|
692
|
-
}
|
|
667
|
+
[self sendDownloadCompletionEvent:taskConfig task:downloadTask error:error];
|
|
693
668
|
|
|
694
669
|
[self removeTaskFromMap:downloadTask];
|
|
695
670
|
}
|
|
@@ -772,30 +747,28 @@ RCT_EXPORT_METHOD(getExistingDownloadTasks: (RCTPromiseResolveBlock)resolve reje
|
|
|
772
747
|
return;
|
|
773
748
|
}
|
|
774
749
|
|
|
775
|
-
if
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
750
|
+
// Safely extract response headers - may be nil if response is not an HTTP response
|
|
751
|
+
NSDictionary *responseHeaders = nil;
|
|
752
|
+
if ([task.response isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
753
|
+
responseHeaders = ((NSHTTPURLResponse *)task.response).allHeaderFields;
|
|
754
|
+
}
|
|
755
|
+
// Use empty dictionary if headers are nil to prevent NSDictionary nil insertion crash
|
|
756
|
+
if (responseHeaders == nil) {
|
|
757
|
+
responseHeaders = @{};
|
|
758
|
+
}
|
|
785
759
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
760
|
+
[self emitOnDownloadBegin:@{
|
|
761
|
+
@"id": taskConfig.id,
|
|
762
|
+
@"expectedBytes": @(expectedBytes),
|
|
763
|
+
@"headers": responseHeaders
|
|
764
|
+
}];
|
|
791
765
|
#else
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
766
|
+
[self sendEventWithName:@"downloadBegin" body:@{
|
|
767
|
+
@"id": taskConfig.id,
|
|
768
|
+
@"expectedBytes": @(expectedBytes),
|
|
769
|
+
@"headers": responseHeaders
|
|
770
|
+
}];
|
|
797
771
|
#endif
|
|
798
|
-
}
|
|
799
772
|
taskConfig.reportedBegin = YES;
|
|
800
773
|
}
|
|
801
774
|
|
|
@@ -830,13 +803,11 @@ RCT_EXPORT_METHOD(getExistingDownloadTasks: (RCTPromiseResolveBlock)resolve reje
|
|
|
830
803
|
|
|
831
804
|
NSDate *now = [NSDate date];
|
|
832
805
|
if ([now timeIntervalSinceDate:lastProgressReportedAt] > progressInterval) {
|
|
833
|
-
if ([self canSendEvents]) {
|
|
834
806
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
835
|
-
|
|
807
|
+
[self emitOnDownloadProgress:[progressReports allValues]];
|
|
836
808
|
#else
|
|
837
|
-
|
|
809
|
+
[self sendEventWithName:@"downloadProgress" body:[progressReports allValues]];
|
|
838
810
|
#endif
|
|
839
|
-
}
|
|
840
811
|
lastProgressReportedAt = now;
|
|
841
812
|
[progressReports removeAllObjects];
|
|
842
813
|
}
|
|
@@ -909,21 +880,19 @@ RCT_EXPORT_METHOD(getExistingDownloadTasks: (RCTPromiseResolveBlock)resolve reje
|
|
|
909
880
|
}
|
|
910
881
|
|
|
911
882
|
// Handle failure
|
|
912
|
-
if ([self canSendEvents]) {
|
|
913
883
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
884
|
+
[self emitOnDownloadFailed:@{
|
|
885
|
+
@"id": taskConfig.id,
|
|
886
|
+
@"error": [error localizedDescription],
|
|
887
|
+
@"errorCode": @(error.code)
|
|
888
|
+
}];
|
|
919
889
|
#else
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
890
|
+
[self sendEventWithName:@"downloadFailed" body:@{
|
|
891
|
+
@"id": taskConfig.id,
|
|
892
|
+
@"error": [error localizedDescription],
|
|
893
|
+
@"errorCode": @(error.code)
|
|
894
|
+
}];
|
|
925
895
|
#endif
|
|
926
|
-
}
|
|
927
896
|
[self removeTaskFromMap:task];
|
|
928
897
|
}
|
|
929
898
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kesha-antonov/react-native-background-downloader",
|
|
3
|
-
"version": "4.1.2
|
|
3
|
+
"version": "4.1.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",
|