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

Commit 6dc1fb8

Browse files
author
Richard Hua
committed
Fix usage of NativeEventEmitter
1 parent d9896a5 commit 6dc1fb8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ios/CodePush/CodePush.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ @implementation CodePush {
2626

2727
#pragma mark - Private constants
2828

29+
// These constants represent emitted events
30+
static NSString *const DownloadProgressEvent = @"CodePushDownloadProgress";
31+
2932
// These constants represent valid deployment statuses
3033
static NSString *const DeploymentFailed = @"DeploymentFailed";
3134
static NSString *const DeploymentSucceeded = @"DeploymentSucceeded";
@@ -296,7 +299,7 @@ - (void)dealloc
296299

297300
- (void)dispatchDownloadProgressEvent {
298301
// Notify the script-side about the progress
299-
[self sendEventWithName:@"CodePushDownloadProgress"
302+
[self sendEventWithName:DownloadProgressEvent
300303
body:@{
301304
@"totalBytes" : [NSNumber
302305
numberWithLongLong:_latestExpectedContentLength],
@@ -537,6 +540,10 @@ - (void)savePendingUpdate:(NSString *)packageHash
537540
[preferences synchronize];
538541
}
539542

543+
- (NSArray<NSString *> *)supportedEvents {
544+
return @[DownloadProgressEvent];
545+
}
546+
540547
#pragma mark - Application lifecycle event handlers
541548

542549
// These two handlers will only be registered when there is

package-mixins.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
2-
import { DeviceEventEmitter } from "react-native";
2+
import { NativeEventEmitter } from "react-native";
33
import RestartManager from "./RestartManager";
44

55
// This function is used to augment remote and local
@@ -15,8 +15,9 @@ module.exports = (NativeCodePush) => {
1515

1616
let downloadProgressSubscription;
1717
if (downloadProgressCallback) {
18+
const codePushEventEmitter = new NativeEventEmitter(NativeCodePush);
1819
// Use event subscription to obtain download progress.
19-
downloadProgressSubscription = DeviceEventEmitter.addListener(
20+
downloadProgressSubscription = codePushEventEmitter.addListener(
2021
"CodePushDownloadProgress",
2122
downloadProgressCallback
2223
);

0 commit comments

Comments
 (0)