Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit b1a176a

Browse files
committed
CR feedback
1 parent 951d6ca commit b1a176a

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

ios/CodePush/CodePush.m

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,19 @@ - (void)applicationWillResignActive
492492
forKey:BinaryBundleDateKey];
493493
}
494494

495+
if (notifyProgress) {
496+
[self setupFrameObserverForDownloadProgress];
497+
}
498+
495499
[CodePushPackage
496500
downloadPackage:mutableUpdatePackage
497501
expectedBundleFileName:[bundleResourceName stringByAppendingPathExtension:bundleResourceExtension]
498502
operationQueue:_methodQueue
499503
// The download is progressing forward
500504
progressCallback:^(long long expectedContentLength, long long receivedContentLength) {
501505
// 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];
506508
}
507509
// The download completed
508510
doneCallback:^{
@@ -512,15 +514,17 @@ - (void)applicationWillResignActive
512514
if (err) {
513515
return reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
514516
}
515-
517+
518+
[self pauseFrameObserver];
516519
resolve(newPackage);
517520
}
518521
// The download failed
519522
failCallback:^(NSError *err) {
520523
if ([CodePushErrorUtils isCodePushError:err]) {
521524
[self saveFailedUpdate:mutableUpdatePackage];
522525
}
523-
526+
527+
[self pauseFrameObserver];
524528
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
525529
}];
526530
}
@@ -760,25 +764,43 @@ - (void)applicationWillResignActive
760764

761765
long long latestExpectedContentLength = -1;
762766
long long latestReceivedConentLength = -1;
767+
BOOL didUpdateProgress = NO;
763768

764769
- (void)didUpdateFrame:(RCTFrameUpdate *)update
765770
{
771+
if (!didUpdateProgress) {
772+
return;
773+
}
774+
766775
// Notify the script-side about the progress
767776
[self.bridge.eventDispatcher
768777
sendDeviceEventWithName:@"CodePushDownloadProgress"
769778
body:@{
770779
@"totalBytes":[NSNumber numberWithLongLong:latestExpectedContentLength],
771780
@"receivedBytes":[NSNumber numberWithLongLong:latestReceivedConentLength]
772781
}];
773-
_paused = YES;
782+
didUpdateProgress = NO;
783+
774784
}
775785

776786
- (void)updateDownloadProgressForNextFrame:(long long)expectedContentLength
777787
receivedContentLength:(long long)receivedContentLength
778788
{
779789
latestExpectedContentLength = expectedContentLength;
780790
latestReceivedConentLength = receivedContentLength;
791+
didUpdateProgress = YES;
792+
}
793+
794+
795+
- (void)setupFrameObserverForDownloadProgress
796+
{
797+
didUpdateProgress = NO;
781798
_paused = NO;
782799
}
783800

801+
- (void)pauseFrameObserver
802+
{
803+
_paused = YES;
804+
}
805+
784806
@end

0 commit comments

Comments
 (0)