diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index b3335d4be..3885fff67 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -26,6 +26,9 @@ @implementation CodePush { #pragma mark - Private constants +// These constants represent emitted events +static NSString *const DownloadProgressEvent = @"CodePushDownloadProgress"; + // These constants represent valid deployment statuses static NSString *const DeploymentFailed = @"DeploymentFailed"; static NSString *const DeploymentSucceeded = @"DeploymentSucceeded"; @@ -296,7 +299,7 @@ - (void)dealloc - (void)dispatchDownloadProgressEvent { // Notify the script-side about the progress - [self sendEventWithName:@"CodePushDownloadProgress" + [self sendEventWithName:DownloadProgressEvent body:@{ @"totalBytes" : [NSNumber numberWithLongLong:_latestExpectedContentLength], @@ -537,6 +540,10 @@ - (void)savePendingUpdate:(NSString *)packageHash [preferences synchronize]; } +- (NSArray *)supportedEvents { + return @[DownloadProgressEvent]; +} + #pragma mark - Application lifecycle event handlers // These two handlers will only be registered when there is diff --git a/package-mixins.js b/package-mixins.js index 78127cfbf..6b18e74eb 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -1,5 +1,5 @@ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; -import { DeviceEventEmitter } from "react-native"; +import { NativeEventEmitter } from "react-native"; import RestartManager from "./RestartManager"; // This function is used to augment remote and local @@ -15,8 +15,9 @@ module.exports = (NativeCodePush) => { let downloadProgressSubscription; if (downloadProgressCallback) { + const codePushEventEmitter = new NativeEventEmitter(NativeCodePush); // Use event subscription to obtain download progress. - downloadProgressSubscription = DeviceEventEmitter.addListener( + downloadProgressSubscription = codePushEventEmitter.addListener( "CodePushDownloadProgress", downloadProgressCallback );