Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_checkForUpdate() {
CodePush.checkForUpdate(CodePushUtils.getDeploymentKey()).then(
remotePackage => {
if (remotePackage == null) {
return;
}
this._syncInNonSilent(remotePackage);
}
);
}
// logic - update - silent
onCheckForUpdate = () => {
this.onClearTimer();
this.props.showDialog(dialogType.UPDATE_DIALOG);
CodePush.checkForUpdate(CONFIG.CODEPUS_KEY)
.then(update => {
if (!update) {
InteractionManager.runAfterInteractions(() => {
this.props.showDialog(dialogType.UP_TO_DATE);
this.timer[1] = setTimeout(() => {
this.props.hideDialog();
}, 1000);
});
} else {
//InteractionManager.runAfterInteractions(() => {
this.props.showDialog(dialogType.GUODU_DIALOG);
// });
InteractionManager.runAfterInteractions(() => {
update.cancelBtn = () => {
this.props.showDialog(dialogType.UPDATE_IGNORED);
this.timer[3] = setTimeout(() => {
componentDidMount() {
CodePush.checkForUpdate()
.then( (update) =>{
if( !update ){
Alert.alert("app是最新版了");
}else {
Alert.alert("有更新哦");
}
});
CodePush.sync({ updateDialog: true, installMode: CodePush.InstallMode.IMMEDIATE },
(status) => {
switch (status) {
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
// this.setState({showDownloadingModal: true});
// this.refs.modal.open();
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
syncImmediate() {
if (!this.state.next) {
CodePush.checkForUpdate(this.props.deploymentKey).then(update => {
if (update) {
console.log("-------CodePush-------检测到新的热更新包--");
console.log(update);
this.setState({ showUpdate: true, updateInfo: update, });
} else if (this.state.showTips) {
this.state.showTips = false;
Toast.show({ title: "已是最新版本!", });
}
});
}
}
syncImmediate = async () => {
const RemotePackage = await CodePush.checkForUpdate();
if(RemotePackage){
this.modal.init(RemotePackage);
}
}
static checkUpdate() {
codePush.checkForUpdate(codePush.CheckFrequency.ON_APP_START)
.then((update) => {
if (update) {
//有更新,提示用户
NavigationUtil.showMessageDialogOverLayOrModal({
title: '检查到新版本',//标题
titleColor: AppConfig.COLOR_THEME,
contentColor: AppConfig.TEXT_COLOR_GRAY,//内容颜色
content: [update.description],//内容
ok: {
text: '立即更新',
callback: () => {
NavigationUtil.dismissMessageDialogOverLayOrModal();
//立即更新
CheckCodePushUpdateUtil.deal(update);
},
},
checkForUpdate = () => {
codePush.checkForUpdate()
.then((update) => {
if (update) {
Alert.alert(
'Update Available',
`Version ${update.appVersion} (${(update.packageSize / 1024 / 1024).toFixed(2)}mb) is available for download`,
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Install & Restart', onPress: this.installUpdate },
],
{ cancelable: false },
);
} else {
Alert.alert('No updates available.');
}
});
}
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 }
);
}
});
}
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')),
onPress: () => localPackage.install(codePush.InstallMode.IMMEDIATE),