Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const syncImmediate = () => {
console.info('[CodePush]syncImmediate: 安装更新并立刻重启应用')
CodePush.disallowRestart() // 禁止重启
CodePush.sync({ installMode: CodePush.InstallMode.IMMEDIATE }, codePushStatusDidChange, progress => {
console.info('[CodePush]codePushDownloadDidProgress: ', progress)
if (progress.receivedBytes >= progress.totalBytes) {
console.info('[CodePush]syncImmediate-强制更新')
CodePush.allowRestart() // 强制更新
}
})
}
static deal(update) {
NavigationUtil.showLoadingOverLayOrModal("0%");
codePush.disallowRestart();
//确定之后,开始下载
update.download(CheckCodePushUpdateUtil.down).then(instance => {
//下载完成了,调用这个方法
console.log("开始安装");
instance.install(codePush.InstallMode.IMMEDIATE).then(() => {
console.log("安装完成");
codePush.notifyAppReady();
codePush.allowRestart();
codePush.restartApp(true);
}).catch(reason => {
CheckCodePushUpdateUtil.error();
});
}).catch((reason) => {
CheckCodePushUpdateUtil.error();
});
}
componentWillUnmount() {
CodePush.disallowRestart();//禁止重启
if (Platform.OS === 'android') {
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
}
}
onBackAndroid = () => {
constructor(props) {
super(props);
CodePush.disallowRestart();
this.listener;
this.currProgress = 0.0;
this.syncMessage = "";
this.state = {
showUpdate: false,
isSync: false,
update: false,
syncStatus: "",
isMandatory: false,
next: false,
currProgress: 0.0,
updateInfo: {},
};
}
toggleAllowRestart() {
this.state.restartAllowed
? CodePush.disallowRestart()
: CodePush.allowRestart();
this.setState({ restartAllowed: !this.state.restartAllowed });
}
toggleAllowRestart() {
this.state.restartAllowed
? CodePush.disallowRestart()
: CodePush.allowRestart();
this.setState({ restartAllowed: !this.state.restartAllowed });
}
componentDidDisappear() {
CodePush.disallowRestart()
}