diff --git a/packages/react-native/ios/HotUpdater/HotUpdater.h b/packages/react-native/ios/HotUpdater/HotUpdater.h index 55660962..029cfc02 100644 --- a/packages/react-native/ios/HotUpdater/HotUpdater.h +++ b/packages/react-native/ios/HotUpdater/HotUpdater.h @@ -9,6 +9,7 @@ @interface HotUpdater : RCTEventEmitter #endif // RCT_NEW_ARCH_ENABLED +@property (nonatomic, assign) NSTimeInterval lastUpdateTime; + (NSURL *)bundleURL; @end diff --git a/packages/react-native/ios/HotUpdater/HotUpdater.mm b/packages/react-native/ios/HotUpdater/HotUpdater.mm index 5a374ee4..e1da974e 100644 --- a/packages/react-native/ios/HotUpdater/HotUpdater.mm +++ b/packages/react-native/ios/HotUpdater/HotUpdater.mm @@ -6,6 +6,15 @@ @implementation HotUpdater { bool hasListeners; } + +- (instancetype)init { + self = [super init]; + if (self) { + _lastUpdateTime = 0; + } + return self; +} + RCT_EXPORT_MODULE(); #pragma mark - Bundle URL Management @@ -179,8 +188,16 @@ - (void)observeValueForKeyPath:(NSString *)keyPath if (task.countOfBytesExpectedToReceive > 0) { double progress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive; - // Send progress to React Native - [self sendEventWithName:@"onProgress" body:@{@"progress": @(progress)}]; + // Get current timestamp + NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000; // Convert to milliseconds + + // Send event only if 200ms has passed OR progress is 100% + if ((currentTime - self.lastUpdateTime) >= 200 || progress >= 1.0) { + self.lastUpdateTime = currentTime; // Update last event timestamp + + // Send progress to React Native + [self sendEventWithName:@"onProgress" body:@{@"progress": @(progress)}]; + } } } }