From 5cab2a84c4867816c73ab289d5893c009b4c16ad Mon Sep 17 00:00:00 2001 From: hupeng Date: Mon, 5 Aug 2019 16:12:42 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8D=87=E7=BA=A7][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=87=E7=BA=A7=E7=BB=84=E4=BB=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/App.js b/App.js index d9c9f2e..c4f2862 100644 --- a/App.js +++ b/App.js @@ -82,6 +82,7 @@ let codePushOptions = { }; export default class MyPage extends Component { + constructor(props) { super(props); this.state = { @@ -105,7 +106,7 @@ export default class MyPage extends Component { //更新函数 async codePushUpdate() { - + CodePush.allowRestart(); await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) .then((metadata: LocalPackage) => { this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); @@ -114,15 +115,18 @@ async codePushUpdate() { this.setState({ versionInfo: "Unknown"}); versionInfo = this.state.versionInfo; }); - await CodePush.disallowRestart(); await CodePush.sync( { mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE, installMode: CodePush.InstallMode.IMMEDIATE}, this.codePushStatusDidChange.bind(this), this.codePushDownloadDidProgress.bind(this) - ); - await CodePush.allowRestart(); - + ).then((status: SyncStatus) => { + if(status!=CodePush.SyncStatus.UP_TO_DATE){ + CodePush.restartApp(); + } + }, (error: any) => { + CodePush.restartApp(); + }); } @@ -527,7 +531,7 @@ render() { return this.getAdView(); } } - +MyPage = CodePush(codePushOptions)(MyPage); const styles = StyleSheet.create({ updatePage:{ flex: 2, @@ -892,5 +896,4 @@ render() { textDecorationLine: 'line-through', color : 'gray' }, - });