mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-13 09:25:36 +08:00
feedback
This commit is contained in:
21
CodePush.m
21
CodePush.m
@@ -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);
|
||||
|
||||
@@ -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("");
|
||||
|
||||
Reference in New Issue
Block a user