This commit is contained in:
Geoffrey Goh
2015-11-25 16:59:02 -08:00
parent 1d0581b0dc
commit 6922cb021d
2 changed files with 33 additions and 21 deletions

View File

@@ -6,7 +6,9 @@
#import "CodePush.h"
@implementation CodePush
@implementation CodePush {
BOOL hasRestartListener;
}
RCT_EXPORT_MODULE()
@@ -358,14 +360,17 @@ RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
rollbackTimeout:rollbackTimeout];
if (installMode == CodePushInstallModeImmediate) {
[self restartPendingUpdate];
[self loadBundle];
} else if (installMode == CodePushInstallModeOnNextResume) {
// Register for app resume notifications so that we
// can check for pending updates which support "restart on resume"
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(restartPendingUpdate)
name:UIApplicationWillEnterForegroundNotification
object:[UIApplication sharedApplication]];
if (!hasRestartListener) {
// Register for app resume notifications so that we
// can check for pending updates which support "restart on resume"
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadBundle)
name:UIApplicationWillEnterForegroundNotification
object:[UIApplication sharedApplication]];
hasRestartListener = true;
}
}
// Signal to JS that the update has been applied.
resolve(nil);

View File

@@ -1,6 +1,7 @@
package com.microsoft.codepush.react;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.NativeModule;
@@ -254,6 +255,8 @@ public class CodePush {
private class CodePushNativeModule extends ReactContextBaseJavaModule {
private LifecycleEventListener lifecycleEventListener = null;
private void loadBundle() {
Intent intent = mainActivity.getIntent();
mainActivity.finish();
@@ -273,22 +276,26 @@ public class CodePush {
}
if (installMode != CodePushInstallMode.IMMEDIATE.getValue()) {
restartPendingUpdate();
loadBundle();
} else if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue()) {
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
@Override
public void onHostResume() {
restartPendingUpdate();
}
// Ensure we do not add the listener twice.
if (lifecycleEventListener == null) {
lifecycleEventListener = new LifecycleEventListener() {
@Override
public void onHostResume() {
loadBundle();
}
@Override
public void onHostPause() {
}
@Override
public void onHostPause() {
}
@Override
public void onHostDestroy() {
}
});
@Override
public void onHostDestroy() {
}
};
getReactApplicationContext().addLifecycleEventListener(lifecycleEventListener);
}
}
promise.resolve("");