Ver a proveniência

[升级][修改]:优化升级组件使用方式

tags/jenkins-front-end-screenad-192-v106^0
hupeng há 5 anos
ascendente
cometimento
5cab2a84c4
1 ficheiros alterados com 10 adições e 7 eliminações
  1. +10
    -7
      App.js

+ 10
- 7
App.js Ver ficheiro

@@ -82,6 +82,7 @@ let codePushOptions = {
}; };


export default class MyPage extends Component { export default class MyPage extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
@@ -105,7 +106,7 @@ export default class MyPage extends Component {


//更新函数 //更新函数
async codePushUpdate() { async codePushUpdate() {
CodePush.allowRestart();
await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
.then((metadata: LocalPackage) => { .then((metadata: LocalPackage) => {
this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode});
@@ -114,15 +115,18 @@ async codePushUpdate() {
this.setState({ versionInfo: "Unknown"}); this.setState({ versionInfo: "Unknown"});
versionInfo = this.state.versionInfo; versionInfo = this.state.versionInfo;
}); });
await CodePush.disallowRestart();
await CodePush.sync( await CodePush.sync(
{ mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE, { mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
installMode: CodePush.InstallMode.IMMEDIATE}, installMode: CodePush.InstallMode.IMMEDIATE},
this.codePushStatusDidChange.bind(this), this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.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(); return this.getAdView();
} }
} }
MyPage = CodePush(codePushOptions)(MyPage);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
updatePage:{ updatePage:{
flex: 2, flex: 2,
@@ -892,5 +896,4 @@ render() {
textDecorationLine: 'line-through', textDecorationLine: 'line-through',
color : 'gray' color : 'gray'
}, },

}); });

Carregando…
Cancelar
Guardar