@@ -492,17 +492,19 @@ - (void)applicationWillResignActive
492
492
forKey: BinaryBundleDateKey];
493
493
}
494
494
495
+ if (notifyProgress) {
496
+ [self setupFrameObserverForDownloadProgress ];
497
+ }
498
+
495
499
[CodePushPackage
496
500
downloadPackage: mutableUpdatePackage
497
501
expectedBundleFileName: [bundleResourceName stringByAppendingPathExtension: bundleResourceExtension]
498
502
operationQueue: _methodQueue
499
503
// The download is progressing forward
500
504
progressCallback: ^(long long expectedContentLength, long long receivedContentLength) {
501
505
// Notify the script-side about the progress
502
- if (notifyProgress) {
503
- [self updateDownloadProgressForNextFrame: expectedContentLength
504
- receivedContentLength: receivedContentLength];
505
- }
506
+ [self updateDownloadProgressForNextFrame: expectedContentLength
507
+ receivedContentLength: receivedContentLength];
506
508
}
507
509
// The download completed
508
510
doneCallback: ^{
@@ -512,15 +514,17 @@ - (void)applicationWillResignActive
512
514
if (err) {
513
515
return reject ([NSString stringWithFormat: @" %lu " , (long )err.code], err.localizedDescription , err);
514
516
}
515
-
517
+
518
+ [self pauseFrameObserver ];
516
519
resolve (newPackage);
517
520
}
518
521
// The download failed
519
522
failCallback: ^(NSError *err) {
520
523
if ([CodePushErrorUtils isCodePushError: err]) {
521
524
[self saveFailedUpdate: mutableUpdatePackage];
522
525
}
523
-
526
+
527
+ [self pauseFrameObserver ];
524
528
reject ([NSString stringWithFormat: @" %lu " , (long )err.code], err.localizedDescription , err);
525
529
}];
526
530
}
@@ -760,25 +764,43 @@ - (void)applicationWillResignActive
760
764
761
765
long long latestExpectedContentLength = -1 ;
762
766
long long latestReceivedConentLength = -1 ;
767
+ BOOL didUpdateProgress = NO ;
763
768
764
769
- (void )didUpdateFrame : (RCTFrameUpdate *)update
765
770
{
771
+ if (!didUpdateProgress) {
772
+ return ;
773
+ }
774
+
766
775
// Notify the script-side about the progress
767
776
[self .bridge.eventDispatcher
768
777
sendDeviceEventWithName: @" CodePushDownloadProgress"
769
778
body: @{
770
779
@" totalBytes" :[NSNumber numberWithLongLong: latestExpectedContentLength],
771
780
@" receivedBytes" :[NSNumber numberWithLongLong: latestReceivedConentLength]
772
781
}];
773
- _paused = YES ;
782
+ didUpdateProgress = NO ;
783
+
774
784
}
775
785
776
786
- (void )updateDownloadProgressForNextFrame : (long long )expectedContentLength
777
787
receivedContentLength : (long long )receivedContentLength
778
788
{
779
789
latestExpectedContentLength = expectedContentLength;
780
790
latestReceivedConentLength = receivedContentLength;
791
+ didUpdateProgress = YES ;
792
+ }
793
+
794
+
795
+ - (void )setupFrameObserverForDownloadProgress
796
+ {
797
+ didUpdateProgress = NO ;
781
798
_paused = NO ;
782
799
}
783
800
801
+ - (void )pauseFrameObserver
802
+ {
803
+ _paused = YES ;
804
+ }
805
+
784
806
@end
0 commit comments