Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CodePush.sync({ installMode: CodePush.InstallMode.IMMEDIATE }, codePushStatusDidChange, progress => {
console.info('[CodePush]codePushDownloadDidProgress: ', progress)
if (progress.receivedBytes >= progress.totalBytes) {
console.info('[CodePush]syncImmediate-强制更新')
CodePush.allowRestart() // 强制更新
}
})
}
instance.install(codePush.InstallMode.IMMEDIATE).then(() => {
console.log("安装完成");
codePush.notifyAppReady();
codePush.allowRestart();
codePush.restartApp(true);
}).catch(reason => {
CheckCodePushUpdateUtil.error();
async componentDidMount() {
CodePush.allowRestart();//在加载完了,允许重启
const data = await Storage.get('themeColor');
if(data){
this.setState({themeColor:data.themeColor});
}
setTimeout(() => {
SplashScreen.hide();
this.syncImmediate(); //开始检查更新
}, 500);
}
export function syncPackage(deploymentKey, showUpdateDialog) {
codePush.allowRestart();
codePush.checkForUpdate(deploymentKey)
.then((remotePackage) => {
if (remotePackage) {
remotePackage.download()
.then((localPackage) => {
if (showUpdateDialog) {
Alert.alert(
I18n.t(ext('newContentAlertTitle')),
I18n.t(ext('newContentAlertMessage')),
[
{
text: I18n.t(ext('laterButton')),
onPress: () => localPackage.install(codePush.InstallMode.ON_NEXT_RESTART),
},
{
text: I18n.t(ext('acceptButton')),
componentDidMount() {
CodePush.allowRestart();
if (this.props.isActiveCheck) {
AppState.addEventListener("change", this._handleAppStateChange);
}
this._handleAppStateChange("active");
this.listener = DeviceEventEmitter.addListener(
"ImmediateCheckCodePush",
e => {
this.setState({ next: false, showTips: true, }, () => {
this._handleAppStateChange("active");
});
}
);
}
componentDidAppear() {
CodePush.allowRestart()
}
toggleAllowRestart() {
this.state.restartAllowed
? CodePush.disallowRestart()
: CodePush.allowRestart();
this.setState({ restartAllowed: !this.state.restartAllowed });
}
async componentWillMount() {
CodePush.allowRestart();
CodePush.checkForUpdate().then((update) => {
if (update) {
Alert.alert(
'Upgrade',
'New update is available. Do you want to upgrade the app?',
[
{ text: 'YES', onPress: () => {} },
{ text: 'NO', onPress: () => this.syncImmediate() },
],
{ cancelable: false }
);
}
});
}
toggleAllowRestart() {
this.state.restartAllowed
? CodePush.disallowRestart()
: CodePush.allowRestart();
this.setState({ restartAllowed: !this.state.restartAllowed });
}