From 6dc1fb8487da565d99b5e7aebffe1b76115f0112 Mon Sep 17 00:00:00 2001 From: Richard Hua Date: Fri, 23 Sep 2016 17:13:51 -0700 Subject: [PATCH] Fix usage of NativeEventEmitter --- ios/CodePush/CodePush.m | 9 ++++++++- package-mixins.js | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index b3335d4..3885fff 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -26,6 +26,9 @@ RCT_EXPORT_MODULE() #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 @@ static NSString *bundleResourceSubdirectory = nil; - (void)dispatchDownloadProgressEvent { // Notify the script-side about the progress - [self sendEventWithName:@"CodePushDownloadProgress" + [self sendEventWithName:DownloadProgressEvent body:@{ @"totalBytes" : [NSNumber numberWithLongLong:_latestExpectedContentLength], @@ -537,6 +540,10 @@ static NSString *bundleResourceSubdirectory = nil; [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 78127cf..6b18e74 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 );